Following code prints 12113411122222,545000
:
Double value = 12113411122222.545421d;
System.out.println(String.format("%f", value));
How to make exact value that the variable value
was assigned to to be printed - 12113411122222.545421
?
Update: I should have said this at the beginning - I know that BigDecimal
needs to be used when precision is needed. However I am using a library which reads a certain type of file and outcome of that is that I get a bunch of attributes from that file. One of the attributes is passed to me from the 3rd party library as a double. After that I am sending attribute value to database which results in attribute value being saved as 1.2113411122222545E13
because value is being converted to String
. So now I am looking for a solution how to 'lose' exponent part and making assumption: if Double.MAX_VALUE
is 1.7976931348623157E308
then it means I might get attribute value with lots of decimal numbers, for example 12113411122222.545421121212212d
, and how do I convert that Double
to String
without 'loosing' any numbers. I suspect this is an issue with Double
's precision but it is counter-intuitive because Double.MAX_VALUE
is 1.7976931348623157E308
. I guess a better knowledge of inner works of Java and numbers in computer systems in general is need to understand the issue.