Live data from Hacker News

Building Payments for an Insurance Startup

moderntreasury.com

1–10 of 38 posts

Re: Building Payments for an Insurance Startup

#3

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

Across major payment processors and subscription management systems like Stripe and through most of the stack, integers are used to represent how much to charge in the smallest currency unit. [1]

With that said, it's better not to reinvent the wheel here and follow the flow, and it's also the safer option— it's better to charge a customer $10 when you meant to charge them $1000, than it is to charge them $1000 when you meant to charge them $10.

[1] https://stripe.com/docs/api/charges/object#charge_object-amo...

Re: Building Payments for an Insurance Startup

#4

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

Using floats to store monetary data is considered 'a very bad idea' in the financial world. Mostly due to how floating point numbers are rounded up/down based on the precision.

https://stackoverflow.com/a/3730040/5536001

Re: Building Payments for an Insurance Startup

#5

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

It's a pain in the butt, but I've realized integers are a good practice. Especially due with oddities of conversions and "maths" like Javascript perform.

Re: Building Payments for an Insurance Startup

#6
post #3

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

Across major payment processors and subscription management systems like Stripe and through most of the stack, integers are used to represent how much to charge in the smallest currency unit. [1] With that said, it's better not to reinvent the wheel here and follow the flow, and it's also the safer option— it's better to charge a customer $10 when you meant to charge them $1000, than it is to charge them $1000 when y…

this isn't re-inventing the wheel. This is how money is safely represented because floating point math is inexact. You end up with cases where the transaction is off ±1¢ (at least)

Re: Building Payments for an Insurance Startup

#7

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

CTO of Modern Treasury here, like the other replies said it's much safer to use integers so we can bypass all the complexity (and gotchas) of floating point.

Re: Building Payments for an Insurance Startup

#9
post #5

Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?

It's a pain in the butt, but I've realized integers are a good practice. Especially due with oddities of conversions and "maths" like Javascript perform.

Fixed precision decimal works as well and may (or may not) require less cognitive load. The nice thing (imho) about using decimal types in code is that since they're uncommon they act as a signal to treat things carefully.
Post reply on HN