#Zeel Darji

1 messages · Page 1 of 1 (latest)

tacit flowerBOT
little bobcat
#

👋 happy to help

#

yes this is due to floating precision in javascript

#

you should use parseInt(154.61 * 100)

quartz plaza
#

Can I use (154.61 *100).toFixed(2)?

little bobcat
#

amounts in cents should be an integer

#

.toFixed(2) would give you a float number

quartz plaza
#

okay got it

#

But what if my number goes like 154.6159

little bobcat
#

are we talking about PaymentIntents or Checkout?

quartz plaza
#

PaymentIntents

little bobcat
#

we don't allow more than 2 decimal points

#

for PaymentIntents

quartz plaza
#

So can I use toFixed(2)?

little bobcat
#

I mean you can charge 154.61 but not 154.6159

quartz plaza
#

parseInt(154.61 * 100) will return string

little bobcat
#

not true

quartz plaza
#

Mean?

#

Sorry my bad

#

Can we user round here?

frigid robin
#

yep, you can

#

what I would suggest though is not using decimals at all, the amounts you store in your database/hard-code as the source for what your products cost should be stored the same way we accept(as integers in the smallest currency unit like cents), and then you wouldn't have this type of problem at all