New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PreciseDecimal to JSON number ends up with long list of decimals #11
Comments
Yes, I'm afraid this is unavoidable because of how It's really down to Apple to fix Decimal and the JSONSerialization APIs, but I wouldn't hold my breath for much longer at this point I'm afraid. |
It is surprising a back end produce a decimal point number and we cannot return back the same decimal value. in this case backend is in golang, using the library Decimal, which JSONEncoder seems to do fine. Android seems to be able to parse properly this JSON from Decimal and the encode it back to send to the same backend. But with Apple, reading breaks in some situations and although with your library now reading works most of the time (if not always), writing back to JSON Number creates those precision issues. Here I can only see two possible options, or our back end do the truncate always (or rounding to the nearest), or we change FE<->BE to use strings instead, but that is a big change (besides network usage). I need to find some time to do some research because my initial finding have very almost none. (We are moving to from FE doing maths operations to MOVE everything to the BE, so no more desaligment between platforms) |
You're correct. Although truncating/rounding is definitely the riskier choice. Footnotes
|
It seems from JSON to the PreciseDecimal we get the proper value but when writing back to JSON.... lots of decimal are added.
Not sure this is a problem for this library though. It is like the JSONEncoder ends up from PreciseDecimal to FLOAT to JSON-Number
The text was updated successfully, but these errors were encountered: