Skip to content

Axios.get: Tail zero is missing #2279

Closed
@549393092

Description

@549393092

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

asingh04 commented on Jul 16, 2019

@asingh04

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

549393092 commented on Jul 17, 2019

@549393092
Author

Thanks!

Chris3y

Chris3y commented on Nov 1, 2019

@Chris3y

So... what's the fix?

yasuf

yasuf commented on Nov 1, 2019

@yasuf
Collaborator

this happens when parsing the response, the trailing 0 after the decimal point are taken out, most likely in

data = JSON.parse(data);
, if you want to do something different instead of the JSON.parse, you can try writing your own transformResponse in your settings

Chris3y

Chris3y commented on Nov 1, 2019

@Chris3y

OK, thank you!

asingh04

asingh04 commented on Nov 2, 2019

@asingh04

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.

locked and limited conversation to collaborators on May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yasuf@Chris3y@asingh04@549393092

        Issue actions

          Axios.get: Tail zero is missing · Issue #2279 · axios/axios