Instead, 5.9049002E14 should be the number 59049000000000.
How to force Java not to distort numbers?
- What does it mean not to distort? Output in the form of a fixed comma, reduce by 2000000, something else? - alexlz
- one@ hitman249, the number is not distorted. That is how it is stored in memory. - Nofate ♦
- try using the BigDecimal type. - alnasfire
- oneFloating Point Arithmetic - AlexeyM
|
3 answers
It can be like this
NumberFormat df = new DecimalFormat("#"); System.out.println(df.format(5.9049002E14));
will be 590490020000000
|
file:
Main.java:
public class Main { public static void main(String[] args) { System.out.println(59049000000000L); } } $ javac Main.java ; java -cp . Main 59049000000000
what am I doing wrong ? :)
- one@shurik, you have a long, and @ hitman249 seems to be double. - avp
|
Alternatively, you can use BigInteger
.
|