Skip to content
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

parseNumbers in lib/processors.js does not return right value for floating point numbers such as '3.4028234663853E+038' #477

Open
aishwaryapanchal opened this issue Aug 30, 2018 · 1 comment

Comments

@aishwaryapanchal
Copy link

<num> <a>-273.17001342773</a> <b>3.4028234663853E+038</b> <c>10864548</c> <d>-0.637</d> </num>

I parsed the above xml file using the parseNumbers of lib/processors.js which gives the following output:
{ num: { a: -273.17001342773, b: 3, c: 10864548, d: -0.637 } }

The property 'b' shows a value 3 instead of 3.4028234663853E+038.

If I replace lib/processors.js function parseNumbers with the following:

if (!isNaN(value)) {
    if (value % 1 === 0 && parseInt(value) == value) {
        value = parseInt(value, 10);
    } else {
        value = parseFloat(value);
    }
}
return value;

Now I get the right value for 'b',
{ num:
{ a: -273.17001342773,
b: 3.4028234663853e+38,
c: 10864548,
d: -0.637 } }

@swftvsn
Copy link

swftvsn commented Oct 1, 2018

There's discussion about this here:
peerlibrary/node-xml4js#12

What we really need is a way to provide custom parsers for integer / float numbers, this way one could determine the best way to handle large numbers, like using big.js or similar library. The default parsers would ofc ourse be the current ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants