-
Notifications
You must be signed in to change notification settings - Fork 11
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
Precision problems in primitive datatypes due to Javascript #12
Comments
True, but that is a problem of JSON representation in general, no? There is no standard way to represent more precise numbers. |
It is not a JSON problem, but a Javascript problem.
A lot of people use some modules to represent big numbers such as bignumber.js, but in this case, IMO we should return the value as |
So you are saying that we should check if totalDigits exists and if that is larger than 15, we should just keep it as a string? Feel free to make a pull request for this. |
Instead of checking
Thanks, when possible I will submit a PR. |
No, I do not like this approach. The main reason why I made this package was because I wanted that resulting JSON has the same schema always. Not that I have to check if once something is an array, and something not, because xml2js made it not an array because there was only one element. In this way I would not like that something is a number and in another document from the same collection of inputs it is a string. So I would be more for approach that if schema is saying that there can be many digits, then we always make strings. Users can change their schema if they want less precision. |
We could do something like this as a workaround. But probably it can also be done manually in a postprocessing step? |
Honestly, I would prefer passing the
After the value is parsed with |
No, I mean, if there is totalDigits which are larger than what JSON can represent with float, then we keep it as a string. And if you want to have this processing of some values to float anyway, then you can postprocess the resulting object manually, instead of having to provide ways to hook into this step here. |
I would say that custom integer / float parsers are more than welcome, so we can plug in our own implementations, like big.js or similar. It is really confusing if the data type can vary, like be a number or string. It would be better if it is only one type. (And provide the option to use custom parsers.) |
As of the XSD specification allows that primitive datatypes
Decimal
,Double
,Float
andInteger
to have a precision with more than 15 significant digits (example is viatotalDigits
).When we are using parseFloat here / here and parseInt here makes the parsed values lose precision (javascript does not support float/number representation with more than 15 digits).
The text was updated successfully, but these errors were encountered: