#kevinx9999-_unexpected

1 messages ¡ Page 1 of 1 (latest)

fickle perchBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1237817237390233661

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

swift lark
#

You can't supply a float type value to unit_amount. It has to be an integer.

#

Can you copy/paste the code that makes this API call?

manic atlas
#

Thanks, here is the code to convert from dollar to cent

  const totalchargeinCents = totalcharge * 100;

#

totalcharge is from the request body, which is a 2 decimal float in string format

#
totalcharge = (rentalfee * 1 + fees * 1).toFixed(2);
swift lark
#

That's likely the line. What does toFixed() do? Is it typecasting to float or decimal?

manic atlas
#

how to ensure that the price would always be a two decimal float then?

#

so users can see $46.90

#

and at the back end, we times that float with 100 to come up with 4690 cents

#

What is your recommendation

swift lark
#

Can you try adding an additional typecast method to the final calculation? Something like Math.round() should do the trick

manic atlas
#

yes, actually I just tried lol

#

not working

swift lark
#

The better solution would be to step through your code and log every mutation of the value out to console so you can see specifically where it's turning into a non-integer

manic atlas
#

ok, let me try it, I'm having trouble to do the localhost test now as I'm traveling

#

thanks for the help!

#

and I think this might be something Stripe can help to remove the pain for dev as well

#

if float is not allowed in that field, just convert it to an integer on your end already

swift lark
#

I'm sure that was considered at some point, though that comes with the added baggage of having to build out an entire system for how to round up/down every conceivable currency on the Earth.

#

Not to say we shouldn't have that, just that it's been this way a long time and I don't foresee that changing anytime soon