Reputation: 25070
In android, as we can see attached figure,
the json that I received from server is "id=-7051563524465472446"
but the code jsonObject.getLong("id")
gives -7051563524465472512.
I can see every getLong
conversion has imprecise result(or lose precision?) in last 4 digits.
Is there anything that I missed?
My settings: java 1.6.0_41, Android 4.1.2, IntelliJ 12 IDE.
Upvotes: 2
Views: 2085
Reputation: 11
I too faced this problem very recently.. Solved it by using the code:
Long.valueOf(jarray.getString((index)))
Upvotes: 0
Reputation: 25070
Long.parseLong(jsonObject.getString("id"))
gives precise result.
Upvotes: 5