Ask Your Question

When converting a Java Long value to a Dart int through the jsonDecode() function in Dart/Flutter, why is there a loss of precision in the resulting value from a JSON string?

asked 2021-07-02 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-15 09:00:00 +0000

david gravatar image

The loss of precision in converting a Java Long value to a Dart int through jsonDecode() function in Dart/Flutter occurs because Java Long values are 64-bit signed integers, while Dart int values are 32-bit signed integers. Therefore, if the Java Long value is greater than 2^31-1 or less than -2^31, it will not fit within a Dart int and will result in a loss of precision. To avoid this, it is recommended to use a String representation for large integer values in JSON encoding and decoding.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-07-02 11:00:00 +0000

Seen: 13 times

Last updated: Aug 15 '21