java中字符串怎么转换成java double类型转换

博客分类:
1如何将字串 String 转换成整数 int?
A. 有两个方法:
1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String],[int radix]);
2). int i = Integer.valueOf(my_str).intValue();
注: 字串转成 Double, Float, Long 的方法大同小异.
2 如何将整数 int 转换成字串 String ?
A. 有叁种方法:
1.) String s = String.valueOf(i);
2.) String s = Integer.toString(i);
3.) String s = "" +
注: Double, Float, Long 转成字串的方法大同小异.
JAVA数据类型转换
ynniebo [收藏]
类型转换 出处
这是一个例子,说的是JAVA中数据数型的转换.供大家学习引
package cn.com.lwkj.erts.import java.sql.Dpublic class TypeChange {
public TypeChange() {
//change the string type to the int type
public static
int stringToInt(String intstr)
integer = Integer.valueOf(intstr);
return integer.intValue();
//change int type to the string type
public static String intToString(int value)
Integer integer = new Integer(value);
return integer.toString();
//change the string type to the float type
public static
float stringToFloat(String floatstr)
floatee = Float.valueOf(floatstr);
return floatee.floatValue();
//change the float type to the string type
public static String floatToString(float value)
Float floatee = new Float(value);
return floatee.toString();
//change the string type to the sqlDate type
public static java.sql.Date stringToDate(String dateStr)
java.sql.Date.valueOf(dateStr);
//change the sqlDate type to the string type
public static String dateToString(java.sql.Date datee)
return datee.toString();
public static void main(String[] args)
java.sql.D
day = TypeChange.stringToDate("");
String strday = TypeChange.dateToString(day);
System.out.println(strday);
JAVA中常用数据类型转换函数 虽然都能在JAVA API中找到,整理一下做个备份。
string-&byteByte static byte parseByte(String s)
byte-&string Byte static String toString(byte b)
char-&string Character static String to String (char c)
string-&Short Short static Short parseShort(String s)
Short-&String Short static String toString(Short s)
String-&Integer Integer static int parseInt(String s)
Integer-&String Integer static String tostring(int i)
String-&Long Long static long parseLong(String s)
Long-&String Long static String toString(Long i)
String-&Float Float static float parseFloat(String s)
Float-&String Float static String toString(float f)
String-&Double Double static double parseDouble(String s)
Double-&StringDouble static String toString(Double)++++++++++++++++++++++++++++++++++++++++++++++++++++++
基本类型有以下四种:int长度数据类型有:byte(8bits)、short(16bits)、int(32bits)、long(64bits)、float长度数据类型有:单精度(32bits float)、双精度(64bits double)boolean类型变量的取值有:ture、falsechar数据类型有:unicode字符,16位对应的类类型:Integer、Float、Boolean、Character、Double、Short、Byte、Long
浏览: 259964 次
哥们,你有这个JBPM3.GA的具体例子么,现在需要和没有sp ...
您这个下载地址好像不对,麻烦你告之一下下载地址或者发到我的邮箱 ...
不好意思哈
真的看不懂 可以大概说下 annota ...
嗯,学习了........
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'Java基础之自动类型转换、强制类型转换Java基础之自动类型转换、强制类型转换产品评价百家号一、自动类型转换1、定义:容量小的数据类型与容量大的数据类型做运算时,容量小的类型会自动转换为容量大的数据类型。自动类型转换的排序:char,byte,short -> int -> long -> float -> double2、当有多种数据类型的数据混合运算的时候,系统会先自动将所有的数据的类型转换成容量最大的那种数据类型,然后再进行计算。3、对于long l = 12;后面不加“l”或“L”也不会报错,因为int比long小,可以自动转换类型。但是对于float f = 12.3;不加“f”或“F”则会报错,因为double比float大,无法进行自动类型转换。4、byte,short,char三种类型之间不会相互转换,三者在计算的时候会默认转换为int类型。例如:byte b = 1; short s = 12; char c = 'a'; int i1 = b + int i2 = b +5、字符串与任何基本数据类型的值之间的运算只能是连接运算(+),基本类型的值会自动转换为字符串类型。二、强制类型转换1、定义:自动类型转换的逆过程,将容量大的数据类型转换为容量小的数据类型。2、使用强制类型转换的时候要加上强制类型转换符(()),括号中为目标数据类型。3、强制类型转换可能会造成精度的降低或者溢出,比如:int i = 1234; byte b =int类型占4个字节,byte类型占1个字节,所以程序会自动截取变量i的末尾8位赋值给变量b,就造成了精度的损失。4、字符串不能直接转换为基本数据类型,但可以通过基本数据类型的包装类实现把字符串转换成基本数据类型。例如:String str = "43"; int i = Integer.parseInt(a);5、boolean类型不可以和其他的数据类型进行相互转换。本文由百家号作者上传并发布,百家号仅提供信息发布平台。文章仅代表作者个人观点,不代表百度立场。未经作者许可,不得转载。产品评价百家号最近更新:简介:中年奥巴马沉迷于科技产品作者最新文章相关文章&nbsp>&nbsp
&nbsp>&nbsp
&nbsp>&nbsp
java中double类型转换成字符串自动格式化成科学计数法
摘要:在使用double类型的时候,常常使用String.valueOf(Doubled)方法来将double转换成String,而String.valueOf(Double)调用的是Double自身的toString()方法。/***Returnsthestringrepresentationofthe&code&double&/code&argument.**Therepresentationisexactlytheonereturnedbythe*&l
在使用double类型的时候,常常使用String.valueOf(Double d)方法来将double转换成String,而String.valueOf(Double)调用的是Double自身的toString()方法。
/** * Returns the string representation of the &code&double&/code& argument. * * The representation is exactly the one returned by the * &code&Double.toString&/code& method of one argument. * * @param d a &code&double&/code&. * @return a string representation of the &code&double&/code& argument. * @see java.lang.Double#toString(double) */ public static String valueOf(double d) {return Double.toString(d); }
而Double自身的toString方法使用FloatingDecimal来对数字进行格式化,代码如下:
public static String toString(double d) {return new FloatingDecimal(d).toJavaFormatString(); }
该方法注释中写到:
* &li&If &i&m&/i& is less than 10&sup&-3&/sup& or greater than or * equal to 10&sup&7&/sup&, then it is represented in so-called * &computerized scientific notation.& Let &i&n&/i& be the unique * integer such that 10&sup&&i&n&/i&&/sup& &;= &i&m&/i& &; * 10&sup&&i&n&/i&+1&/sup&; then let &i&a&/i& be the * mathematically exact quotient of &i&m&/i& and * 10&sup&&i&n&/i&&/sup& so that 1 &;= &i&a&/i& &; 10. The * magnitude is then represented as the integer part of &i&a&/i&, * as a single decimal digit, followed by '&code&.&/code&' * (&code&'&;#92;u002E'&/code&), followed by decimal digits * representing the fractional part of &i&a&/i&, followed by the * letter '&code&E&/code&' (&code&'&;#92;u0045'&/code&), followed * by a representation of &i&n&/i& as a decimal integer, as * produced by the method {@link Integer#toString(int)}.
可以很明确的看到,如果数字大于10的7次方或者小于10的-3次方,就会使用科学计数法。这个在很多时候很适用,同时在很多地方也让很多人很头疼。想要避免这个问题,就要自己使用格式化类去重新格式化。最简单的使用DecimalFormat类去格式化,用这个可以很容易的得到不转换成科学计数法的字符串。
DecimalFormat df = new DecimalFormat(&###0.0#&);//最多保留几位小数,就用几个#,最少位就用0来确定String s=df.format(d);
这样就可以了~
以上是的内容,更多
的内容,请您使用右上方搜索功能获取相关信息。
若你要投稿、删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内给你回复。
云服务器 ECS
可弹性伸缩、安全稳定、简单易用
&40.8元/月起
预测未发生的攻击
&24元/月起
为您提供0门槛上云实践机会
你可能还喜欢
你可能感兴趣
阿里云教程中心为您免费提供
java中double类型转换成字符串自动格式化成科学计数法相关信息,包括
的信息,所有java中double类型转换成字符串自动格式化成科学计数法相关内容均不代表阿里云的意见!投稿删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内答复
售前咨询热线
支持与服务
资源和社区
关注阿里云
InternationalJava中String与基本类型转换_百度文库
赠送免券下载特权
10W篇文档免费专享
部分付费文档8折起
每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Java中String与基本类型转换
你可能喜欢&nbsp>&nbsp
&nbsp>&nbsp
&nbsp>&nbsp
如何实现将java中Double类型的科学计数法转换为指定格式显示?
摘要:1.转为指定格式显示:/***将double类型的科学计数法转换成指定格式的正常字符串*start转换double类型的格式为:两位小数*@paramd*@returnString*@authorljp*/publicstaticStringformatToTwo(doubled){DecimalFormata=newDecimalFormat(&#,##0.00&);StringfrmStr=a.format(d);returnfrmS}2.对于位
1.转为指定格式显示:
* 将double类型的科学计数法转换成指定格式的正常字符串
* start 转换double类型的格式为:两位小数
* @param d
* @return String
* @author ljp
public static String formatToTwo(double d) {
DecimalFormat a = new DecimalFormat(&#,##0.00&);
String frmStr = a.format(d);
return frmS
2.对于位数不大,不是科学计数法的字符串类型,如果位数不足两位的数字,自动添0至两位:
public static String formatToTwo(String frmStr) {
String[] frmStrArray =
if (frmStr.contains(&.&)) {
frmStrArray = new String[2];
frmStrArray[0] = frmStr.substring(0, frmStr
.indexOf(&.&));
frmStrArray[1] = frmStr.substring(frmStr
.indexOf(&.&) + 1, frmStr.length());
if (frmStrArray != null &;&; 1 & frmStrArray.length) {
String firStr = frmStrArray[0];
String secStr = frmStrArray[1];
if (secStr != null &;&; 2 & secStr.length()) {
int secStrLen = secStr.length();
if (secStrLen == 1) {
secStr = secStr + &0&;
if (secStrLen == 0) {
secStr = &00&;
frmStr = firStr + &.& + secS
frmStr = frmStr + &.00&;
return frmS
注:在java中,把一个double或者BigDecimal的小数转换为字符串时,经常会用科学计数法表示,而我们一般不想使用科学计数法,可以通过:DecimalFormat a = new DecimalFormat(&#,##0.&);
System.out.println(a.format(1));的方式来格式化输出字符串。对于BigDecimal的小数,如果制定精度&=6, 则可以放心的使用其toString函数。但是对于&6的精度,有可能会使用科学计数法,查看器代码有如下判断:long adjusted = -(long)scale + (coeff.length-1);
if ((scale &= 0) &;&; (adjusted &= -6)){
非科学计数法的toString.
}其中scale指BigDecimal的精度,coeff对应使用BigInteger存储的值的toString字符串, coeff = intVal.abs().toString().toCharArray(),也就是说BigDecimal在对应精度下的整数值,例如BigDecimal ob = new BigDecimal(0.), ob的精度为7, 则coeff=&1&;如果ob=new BigDecimal(0.), 则coeff=&1000001&;如果ob=new BigDecimal(0.), 则coeff=&0&;
以上是的内容,更多
的内容,请您使用右上方搜索功能获取相关信息。
若你要投稿、删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内给你回复。
云服务器 ECS
可弹性伸缩、安全稳定、简单易用
&40.8元/月起
预测未发生的攻击
&24元/月起
为您提供0门槛上云实践机会
你可能还喜欢
你可能感兴趣
阿里云教程中心为您免费提供
如何实现将java中Double类型的科学计数法转换为指定格式显示?相关信息,包括
的信息,所有如何实现将java中Double类型的科学计数法转换为指定格式显示?相关内容均不代表阿里云的意见!投稿删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内答复
售前咨询热线
支持与服务
资源和社区
关注阿里云
International}

我要回帖

更多关于 java字符串转换double 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信