News for hackers. Stuff that matters.
Re:Building Payments for an Insurance Startup by saarons on Wednesday July 31, 2019 @12:42PM (#20575897)
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 by jfengel on Wednesday July 31, 2019 @02:42PM (#20577009)
Seems to me it would be even safer to represent it as an object: amount: { dollars: 60, cents: 00 }

or some such. In addition to being ready for foreign currencies, you can build in type safety to ensure that nobody does something meaningless like "60 dollars times 90 dollars", and prevents you from accidentally asking for $6,000 when you meant $60. It's less efficient, to be sure, and you have to implement all of those operations like "addition", but it's a case where being excruciatingly, provably correct seems more important than a few extra bucks on servers.

Re:Building Payments for an Insurance Startup by ThrustVectoring on Wednesday July 31, 2019 @03:29PM (#20577430)
If you store integer amounts of the smallest currency subdivision, you're already ready for foreign currencies. You just need to specify how each currency converts from a representation like `$60` to an integer count like `6000`. This even accounts for non-decimal currencies (which basically aren't in modern use) - just set a conversion factor of 500 or 60 or whatever instead of 100.
Re:Building Payments for an Insurance Startup by dvlsg on Wednesday July 31, 2019 @06:26PM (#20579225)
Probably worth noting that in some cases the currency alone isn't enough information.

For example, gas stations using USD often use more than 2 digits of precision.

I suspect (and hope) that situation is reasonably rare, though.

Re:Building Payments for an Insurance Startup by conductr on Wednesday July 31, 2019 @11:44PM (#20580923)
They can’t bill that way though and this is a monetary transfer api

Just like how the complex algorithm of determining insurance rates is likely to yield a long decimal, it has to be rounded to translate to a currency. Heck even things like sales tax being a % requires a rounding calc to be done on majority of transactions before the monetary units are tallied for the “total”

Re:Building Payments for an Insurance Startup by ThrustVectoring on Thursday August 01, 2019 @12:54PM (#20585753)
That's a price, not a balance or amount transferred. Any sub-cent stuff is handled internally by the gas station, then rounded to the nearest cent and transferred to external banking APIs. The gas station is free to use whatever representation it wants for the price and quantity, so long as it rounds to the nearest cent before pushing to the API.
Re:Building Payments for an Insurance Startup by dvlsg on Tuesday August 06, 2019 @03:57PM (#20628908)
Sure, I probably should have specified that I meant in general when handling money, not necessarily specifically for handling payment API calls. I've worked on a system that kept track of arbitrary precision separately while using integers to store the values. Worked reasonably well, all things considered.

But you're right, we wouldn't have expected to be able to call something like stripe with that same arbitrary precision. It was all internal pricing.

Re:Building Payments for an Insurance Startup by briffle on Wednesday July 31, 2019 @03:14PM (#20577259)
Not every currency has a decimal amount. For example, there are no decimals in the Japanese yen.

Not to mention then you need to translate that for all the currencies, {pounds: 60, <whatever a decimal of a pound is>: 00 }

Re:Building Payments for an Insurance Startup by jfengel on Wednesday July 31, 2019 @03:53PM (#20577743)
Yes, exactly. That's the advantage. You need to display pounds different from yen and dollars and bitcoins. It's good to have the code say, "Whoops, I was only expecting dollars and cents, and I'm not prepared for this thing you handed me" rather than accidentally displaying the wrong thing.

At the very least I'd want the currency marked. And once you're representing currency as a structure/object rather than a bare integer, you've got a lot more opportunities to ensure safety.

Re:Building Payments for an Insurance Startup by unilynx on Wednesday July 31, 2019 @05:20PM (#20578669)
Or just use strings. That's what we do for basic webshop math - any naive attempt at doing eg a multiplication will break, requiring you to use the supplied math library (just like with objects...)

But: with strings you still have pass-by-value. So you can pass the values anywhere without worrying that whoever received the values will be modifying your object. And we still have the infinite range that integers can't give, which is especially useful when doing the multiplications for VAT and coupon codes etc..

The only remaining danger is that '+' works on strings, but we should notice those fast enough - it hasn't been a real issue yet.

(And if we need to start optimizing things at some point, I'd expect to have a better starting point when the data is already in a string than if we have to copy around objects all the time)