3 ms·
Or, just use IEEE 754 decimal types? That's what they were built for.
by kstenerud 9y ago
Or, just use IEEE 754 decimal types? That's what they were built for.
- FreeFull 9y agoThose still have limited precision, and the precision varies depending on how big the number is, which isn't suitable for money
- nokcha 9y agoIEEE 128-bit decimal can handle a precision of 34 significant figures (decimal digits). You can store a million times the world GDP (1e6 * US$75.59 trillion) accurate to picodollars. How much more precision do you need?
- smitherfield 9y agoAnd before someone says "hyperinflation," you could also store world GDP in nano-Zimbabwean dollars (with 1 USD = 6.69e11 ZWL).
- stephencanon 9y agoThe entire raison d'être of floating-point is that, unlike integers, the precision does not vary with the magnitude[1]. 1. except for underflow, which reasonable financial computations never encounter, because their inputs are well-scaled.
- kolpa 9y agoThat only works if your entire program is in one currency, and you don't use any non-currency integers in your program . The OP is talking about currency conversion and type-safety.