#Cola Pop

1 messages ยท Page 1 of 1 (latest)

near rivetBOT
oblique glade
#

Could you share the Payment Intent ID (pi_xxx) that was charged with $33.36?

grizzled mountain
#

give me a moment, and lets me double check first

#

@oblique glade im back

#

we had pi_3MYV8gHzlMR8SHJI0jS0bBxt and pi_3MYWqnHzlMR8SHJI1Bhisq2H

oblique glade
#

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.

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?

grizzled mountain
#

@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 ๐Ÿ˜„ )

  1. we throw this object:
{
 amount: (totalAmount.toFixed(2) * 100),
 currency: currency_code_here
}
  1. 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
}
oblique glade
#

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)

grizzled mountain
#

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

oblique glade
#

No problem! Happy to help ๐Ÿ˜„

grizzled mountain
#

๐Ÿบ have a nice day ! @oblique glade