Java How to disable rounding in decimalformat
•
Java
Can I disable rounding in decimalformat?
For example:
DecimalFormat f = new DecimalFormat();
f.parSEObject( “123456789012345.99”);
The result is 1.2345678901234598e14
Java version "1.6.0_21"
Solution
This has nothing to do with the functionality of Java This is due to the limited precision of IEEE 64 bit double floating point numbers In fact, all data types have their precision limits Home is bigger than others
double d = 123456789012345.99; System.out.println(d);
1.2345678901234598E14
If you want to be more precise, use BigDecimal
BigDecimal bd = new BigDecimal("123456789012345.99"); System.out.println(bd);
123456789012345.99
Even BigDecimal has limits, but they are far more than you or anyone else needs (about 2 billion)
Edit: the largest known prime number is suitable for BigDecimal http://primes.utm.edu/largest.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码