Scientific notation is a valid representation for floating point ("real") numbers. Furthermore, JSON allows numbers to be represented in scientific notation; see the JSON syntax graphs on json.org.
There is no need to round the number or convert to not use scientific notation ... to make it acceptable in JSON format.
If you create the JSON using one of the many Java JSON parser / unparser libraries, they will take care of the formatting.
If you are formatting the JSON by hand, then Double.toString(double)
will produce an acceptable rendering for your JSON.
If you insist on avoiding scientific notation, there are a variety of ways to do it. A simple way is String.format("%f", value)
. Others are described in How do I print a double value without scientific notation using Java?.
However, beware of rounding. The string 0.0009
is NOT a valid representation of 9.090909090909097E-4
. You have discarded roughly 13 decimal digits of precision. The former differs from the latter by almost 10%.
In short, while 0.0009
looks nice, it is mathematically very, very wrong.