Double.parseDouble("-1.23E-3") = -1.23E-3
解决方案 »
- 谁给我个CAD软件的程序
- 在练习终于到的问题!请教,不胜感激!
- 关于异常捕捉的一个问题
- 请教大家,我在自定义输入类的几个不明白问题(我自己写了个输入类,但有几个毛病解决不了,特向大家请教)
- 请提示一下实现浏览器接收图片的方法
- 用java做个gui,全部用手写代码做么?
- 关于绘图的问题, 不是高手请不要进啊!!!
- 请问在哪可以下到jbulider的教学? 书 马上给分!
- JAVA 数组问题,TOO easy!
- 初学者,接触过多门语言,现在不知道学哪一们好,但看好Java,请大家给点意见说点看法~
- JBuilder 9 中整合 jdk1.5 求助!!!高手来
- 有关DecimalFormat格式化字符串的问题???
{
public static void main(String args[])
{
System.out.println(Double.parseDouble("-1.23E-3"));
}
} //输出
-0.00123
import java.text.DecimalFormat;
public class Change {
public static void main(String[] args) throws Exception{ DecimalFormat df = new DecimalFormat("#.00");
double a = 1111111111.11;
double b = 1111111111.11;
String ab = df.format(a + b);
System.out.println(ab);
System.out.println("科学计数法:"+(a+b));
}
}
{
public static void main(String args[])
{
System.out.println(Double.parseDouble("-1.23E-3"));
System.out.println( (new Double("-1.23E-3")).toString() );
}
} //输出
-0.00123
-0.00123
class Test
{
public static void main(String args[])
{
System.out.println(Double.parseDouble("-1.23E-12"));
System.out.println( (new Double("-1.23E-12")).toString() );
}
} //输出
-1.23E-12
-1.23E-12
double d = 12345678.12345;
String dStr = df.format(d);
这样dStr就变成了:1234567.1234,而不会是:1.234567812345E7 的形式了。
但是这些输出都是String对象。如果转换成double数据,又会变成原来一样了:(
{
try
{
double newValue = value;
String newValueStr = String.valueOf(newValue);
int eindex = newValueStr.toUpperCase().indexOf("E");
String format = "";
if(eindex == -1)
{
return newValueStr;
}
else
{
String cardinalNumberStr = newValueStr.substring(0,eindex);
String exponentialStr = newValueStr.substring(eindex + 1);
if(exponentialStr.startsWith("+"))
{
exponentialStr = exponentialStr.substring(1);
}
int exponential = Integer.parseInt(exponentialStr);
if(exponential > 0)
{
if((cardinalNumberStr.length() - 2 - exponential) > 0)
{
format = "#.";
for(int i=0; i<(cardinalNumberStr.length() - 2 - exponential); i++)
{
format += 0;
}
}
else
{
format = "#.0";
}
}
else if(exponential < 0)
{
format = "0.";
for(int i=0; i<(cardinalNumberStr.substring(cardinalNumberStr.indexOf(".") + 1).length() - exponential); i++)
{
format += 0;
}
}
else
{
format = "#.0";
}
if(format.length() == 2)
{
format += 0;
}
DecimalFormat df = new DecimalFormat(format);
return df.format(newValue);
}
}
catch(Exception e)
{
e.printStackTrace();
return String.valueOf(value);
}
}