#Cola Pop
1 messages ยท Page 1 of 1 (latest)
Could you share the Payment Intent ID (pi_xxx) that was charged with $33.36?
give me a moment, and lets me double check first
@oblique glade im back
we had pi_3MYV8gHzlMR8SHJI0jS0bBxt and pi_3MYWqnHzlMR8SHJI1Bhisq2H
In pi_3MYV8gHzlMR8SHJI0jS0bBxt, Stripe charged 3336 based on the amount set in the Payment Intent creation request: https://dashboard.stripe.com/logs/req_Z0W23BxRwDptDj
If you multiply 33.37*100 that leads to 3336.999999, it's likely the due to JavaScript floating precision error.
- https://stackoverflow.com/questions/14727839/javascript-floating-calculation-error
- https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript
It has nothing to do with Stripe library, but the floating precision in JavaScript. Could you share the code how you convert the float to integer?
@oblique glade ah yep, I understand its the precision issue in Javascript, but just wondering if have other way.
Anyway, lets me share you snipped how we calculate the number before throw it to Stripe JS Library.
ok we have two way in our system, but basically both having same issue, here is the snippet that I rewrite a bit because of the security yadda yadda (if you know what I mean ๐ )
- we throw this object:
{
amount: (totalAmount.toFixed(2) * 100),
currency: currency_code_here
}
- in other side, we have a bit complicated code in our legacy function that still used (and have same issue), this is the object we throw:
{
amount: parseInt(`${Number((amount+tax).toFixed(2)) * 100}`),
currency: currency_code_here
}
Thanks for sharing. toFixed simply convert to the fixed position. I'd recommend to round the number after multiplying 100. For example,
Math.round(totalAmount.toFixed(2) * 100)
Yup, I guess the only way is to do from JS side and also doing something like you recommendation ๐
thanks a lot River, you are very helpful ๐
we can close this ticket/thread on your side if needed (to be honest I dont know how this is work in your side) haha
No problem! Happy to help ๐
๐บ have a nice day ! @oblique glade