开发者

Problem in using float on Android

I am going to develop a calculator on android platform, it is fine in calculating numbers less than 1000000, when I tried to add 1000000 with 0, the result is "1.0000E7"?! I try to change the type of result from float to double, 开发者_开发知识库but the problem is still here, I try to use long, result becomes normal, but it cannot calculate decimal place anymore....


For your output use String.format(String format, Object... args)

and see Formatter for an overview on how to use the different placeholders/format specifiers (you will be especially interested in Floating-point conversions, ctrl-f it).


The calculation and the result are completely fine. 1.0000E7 is the correct result. See Scientific Notation for more information. If you don't want the number to be shown this way you have to change the way you create the output string out of your result.


The output just switched over to scientific notation. The solution is hidden in that part of your code that prints the result on the screen (widget).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜