Decimal point is not preserved after parsed to json.
shikeiyan opened this issue · comments
[] 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?
Description
Tried out some ways below but still not working:
- add options leadingZeros: false
- add options parseNodeValue: false
- upgrade to latest version
Current version used: 4.0.2
Code
const { XMLParser, XMLBuilder } = require("fast-xml-parser");
const options = {
ignoreAttributes : false,
preserveOrder: true,
trimValues: false
};const Parser = new XMLParser(options);
const Builder = new XMLBuilder(options);const XMLUtils = {
parse: (xmlString) => {
return Parser.parse(xmlString); // produce json
},
build: (json) => {
return Builder.build(json); // produce xml string
},
}
const xmlString =
<correctResponse><value>33.00</value></correctResponse>
;
const xmlJson = XMLUtils.parse(xmlString);
console.dir(xmlJson, {depth:null});
Output
[ { correctResponse: [ { value: [ { '#text': 33 } ] } ] } ]
Expected data
[ { correctResponse: [ { value: [ { '#text': 33.00 } ] } ] } ]
We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.
Please check https://github.com/NaturalIntelligence/strnum
Hi @amitguptagwl , I have tried to pass in options with leadingZeros: false and the decimal point is not preserved.
Refer to the attachment below, the issue is replicable in online tool as well with unchecked "parse number with leading zeros".
To keep a number as "33.00", it should not be parsed as number but as string only.
Hi @amitguptagwl , may I know any workaround or any fix for this on your side?