0

I got a different type of numbers in my json string. So parsing this numbers with JSONObject leads to 3.7E-4-like representation of this numbers. I prefer to see numbers as a string. What to do? How to prevent such conversion?

{"data":
    {"number1":0.0004,
     "number2":0.00038,
     "number3":0.00037
}}
Outofdate
  • 635
  • 5
  • 16

2 Answers2

0

Simply, create a string before putting your number to JSON.

or

int number = 0;
json.put(number + "");

Can you give an example number, not represented like above?

slhddn
  • 1,917
  • 1
  • 15
  • 21
0

I think it is some limitation of this particular json library. As a workaround, you could convert parsed values to BigDecimal and use it, unless the double conversion does not lose precision significantly.

For more details read this: How to prevent JSONObject from json.jar converts decimal numbers string into double

Community
  • 1
  • 1
kan
  • 28,279
  • 7
  • 71
  • 101