I’m looking at some code that was using a double variable to store the results of (360-359.9998779296875) which is 0.0001220703125. The double variable stores this as -1.220703125E-4. When I use a BigDecimal its stored as 0.0001220703125. Why does double store it as -1.220703125E-4?
Share
I won’t mention precision issues here but only the way the numbers get printed.
As explained in the javadoc of
Double#toString:Whereas the javadoc of
BigDecimal#toString:You can try this little program to check the various output formats and, in particular, the threshold at which the representation switches from standard notation to scientific notation is not the same in the two classes.
Output:
Code: