Should parse long number string as string instead of number
See original GitHub issueChecklist
- Have you asked your question on Stackoverflow or similar forum?
- Are you running the latest version?
- Have you included sample input, output, error, and expected output?
- Have you checked if you are using correct configuration?
- Did you try online tool?
Input
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<LongNumberString>420926189200190257681175017717</LongNumberString>
</Root>
Code
const { getTraversalObj, convertToJson } = require('fast-xml-parser');
const options = { attributeNamePrefix: '$', ignoreAttributes: false };
const x2j = xml => convertToJson(getTraversalObj(xml, options), options);
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<Root>
<LongNumberString>420926189200190257681175017717</LongNumberString>
</Root>
`;
const json = x2j(xml);
console.log(json);
Output
{ Root: { LongNumberString: 4.209261892001902e+29 } }
expected data
{ Root: { LongNumberString: "420926189200190257681175017717" } }
Would you like to work on this issue?
- Yes
- No
Bookmark this repository for further updates.
Description
I can help to enhance the parser if you think this is correct.
IMO, the scientific notation can not represent the value in the XML. The type should be string if the number string is too long (more than Number.MAX_SAFE_INTEGER
).
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How do I parse a long number string to just a number?
The parseInt() function takes the first number of the string and removes decimal places, it returns an integer:.
Read more >How to convert a string to a number - C# Programming Guide
You convert a string to a number by calling the Parse or TryParse method found on numeric types ( int , long ,...
Read more >Number() vs parseInt() - this vs that
Both Number() and parseInt() are often used to convert a string to number. Differences. Number() converts the type whereas parseInt parses the value...
Read more >7 ways to convert a String to Number in JavaScript
1. Using parseInt() parseInt() parses a string and returns a whole number. Spaces are allo...
Read more >How to Convert a String to a Number in JavaScript
One way to convert a string into a number would be to use the Number() ... Instead of multiplying by 1, you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ShinyChang please use option
parseTrueNumberOnly : true
Thanks for the suggestion. Will implement it in a future version.