Using JSONObject to read json response from server. The server returns some decimal number. Normal numbers are not a problem, but the problem arises when there is a decimal number of the form 0.00068 . Numbers, such as 0.00068 , are automatically stored in the Double object, and when an attempt is made to get such a number, the "computerized scientific notation" of this number is returned, that is 6.8E4, even if the number is available as a double using the getDouble(index) method or as a String with the getString(index) method.
We tried this method of converting a double value to a string, but eliminated this tecinique, because some positive rounding was added when Double converted to BigDecimal . This can be eliminated by rounding when scaling to BigDecimal.ROUND_CEILING . But I do not want to scale and I want to have the original values, since the actual value is a small decimal number, and the server guarantees that after the decimal point the number will not exceed 6 digits.
BigDecimal big = new BigDecimal(new Double(0.00680)); System.out.println(big.toPlainString());
Could there be some way to get the actual String value of Double, which is the number 0.00680 without scaling, or can we prevent JSONObject interpreting the numbers in their respective number classes.
Thanks in advance.
source share