Closed
Description
When call axios.get() method, I checked the response data in the chrome dev tool.
see below example data.
{"flowId":"3100000002","stdQty":100.000,"netPrice":10.00}
But when using the syntax
axios.get('/orders/123').then((response) => {
console.log(response.data)
}).catch((error) => {
console.log(error)
})
When checking the response data, you will find stdQty = 100 and netPrice = 10.
So the tail zero is missing.
How can I keep them?
Activity
asingh04 commentedon Jul 16, 2019
I guess this is a javascript feature of dropping the trailing zeros of float type data.
So the trailing zeros after the decimal points get dropped and the value becomes of Int type
549393092 commentedon Jul 17, 2019
Thanks!
Chris3y commentedon Nov 1, 2019
So... what's the fix?
yasuf commentedon Nov 1, 2019
this happens when parsing the response, the trailing 0 after the decimal point are taken out, most likely in
axios/lib/defaults.js
Line 61 in 0979486
transformResponse
in your settingsChris3y commentedon Nov 1, 2019
OK, thank you!
asingh04 commentedon Nov 2, 2019
Yes, there is no fix for it as it is not a bug of any kind. It just how JS works.
If you really need to preserve the 'n' decimal places, you have to use
Number.prototype.toFixed(n)
in your response handler function to get the even trailing 0s.