Here's a snippet of data returned by the API. The amount tendered in the transaction was actually $1.00 USD, but the API returns a value of 100. Is this normal? Should I expect to have to add the decimal and decimal places, myself?

{
    "type": "CASH",
    "name": "Cash",
    "total_money": {
        "currency_code": "USD",
        "amount": 100
    },
    "tendered_money": {
        "currency_code": "USD",
        "amount": 100
    }
}
有帮助吗?

解决方案

The problem is that lots of languages, Javascript included, don't have decimals. They have floats instead. And you should never do monetary calculations (that you care about) with floats due to the floating point problem:

As such, returning the rates in cents is a good way to remind programmers of this and avoid the temptation of doing financial calculations in floats.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top