using floats for currency based applications is a bad idea
geggleto opened this issue · comments
tldr; never use floats for money/currency applcations/libraries.
Floats introduce imprecision. For financial transactions you never want imprecision.
Reference: https://dzone.com/articles/never-use-float-and-double-for-monetary-calculatio#:~:text=Float%20and%20double%20are%20bad,use%20them%20for%20monetary%20calculations.&text=All%20floating%20point%20values%20that,it%20is%20in%20the%20memory.
How to fix, use Zero-Decimal currency format
Zero-decimal currencies
All API requests expect amounts to be provided in a currency’s smallest unit. For example, to charge 10 USD, provide an amount value of 1000 (i.e., 1000 cents).
For zero-decimal currencies, still provide amounts as an integer but without multiplying by 100. For example, to charge ¥500, provide an amount value of 500.
Reference: https://stripe.com/docs/currencies
@geggleto not sure if this apply to Paypal API. they don't seem to mention this in their docs.