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.
Building Payments for an Insurance Startup
21–30 of 38 posts
Re: Building Payments for an Insurance Startup
#22Earlier quoted context omitted.
Fixed-point vs floating-point arithmetic! In scientific applications, you want to preserve precision regardless of the system of units (i.e. scale). For example, 1.23 meters is 1.23e2 cm or 1.23e-3 km. The side effect of this is the roundoff error of arithmetic operations. Floating point operations are not commutative or associative. In financial transactions on the other hand, we always need only 2 decimal places. S…
Also in Fintech. In some cases it is actually necessary to have more than 2 decimal places. For example, interest accrued daily, but only ‘compounded’ monthly. In those cases, it is necessary to maintain far more than the 2 decimal places for the daily accruals. The best type to use here would be BigDecimal or equivalent. These ultimately serialise to infinite length strings.
{ "amount": 12345, "exponent": 4 }
We could do that or something like: { "amount": "1.2345" }Re: Building Payments for an Insurance Startup
#23Earlier quoted context omitted.
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.
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 th…
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)
Re: Building Payments for an Insurance Startup
#24Earlier quoted context omitted.
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 th…
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.
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
#25Re: Building Payments for an Insurance Startup
#26This is a great read from Modern Treasury. One thing highlighted in this article that the industries not always talk about, is the concept of "Payment Ops". This is critical in FinServ organizations from my own experience. Any good and reliable payments infra is a function of technology, people, and process, and you need good tooling to streamline the whole workflow that involves engineering, finance, credit and comp…
Re: Building Payments for an Insurance Startup
#27Source: built a fairly large insurance company with zero client money accounts by using Stripe Connect
Disclosure - we are locked into processing card payments with Stripe only, but have no incentive to say nice things about them
Re: Building Payments for an Insurance Startup
#28Stripe Connect makes all of this stuff veeeeery easy. No need to test up trust/FBO bank accounts/etc. for client money - just allocate money to accounts held in the name of the correct parties. Source: built a fairly large insurance company with zero client money accounts by using Stripe Connect Disclosure - we are locked into processing card payments with Stripe only, but have no incentive to say nice things about t…
with this you mean you don't get money from them to promote them. Please correct me if I'm wrong.
Re: Building Payments for an Insurance Startup
#29Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?
Re: Building Payments for an Insurance Startup
#30Why do you use integers to represent monetary values? It seems like $600 is represented as 60000. Or is that a typo?
https://developers.google.com/standard-payments/reference/gl...