开发者

DecimalFormat WITHOUT scientific notation

I have a DecimalFormat like this:

DecimalFormat df = new DecimalFormat("#,###开发者_如何学编程.###");

Then I have 3 methods which just return a float value for time, potential and current, with many decimals in case of the two last ones. So I'm trying to get an output message with the 3 values formated, so:

System.out.println("t="+df.format(getTime())+"(s), v="+df.format(getPotential())+"(V), i="+df.format(getI())+"(A)");

Time just count seconds from 0 to 10, without any decimal, and looks ok until it gets to 10. Then it shows 1E+1. I just don't understand why, since I have read at the API and it shouldn't be in scientific notation if I don't use an 'E' character at the DecimalFormat.

Also, potential goes from 0 to a certain value, using 3 decimals. Looks OK, but from 0 to 0.01, it appears with 4 decimals, being the last one always 0.

Any explanation to this behaviour of DecimalFormat? What am I doing wrong?


Maybe it would be simpler to use printf in your case :

System.out.printf("t=%d(s) v=%.2f(V) i=%.2f(A)\n", getTime(), getPotential(), getI());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜