re: What Elm and Rust Teach us About the Future VIEW POST


Really interesting post, thanks! Just out of interest, why would you recommend using decimal types for representing currency? I’ve always found this to be problematic with rounding etc.


Decimal types differ from floating-point types in that they have a fixed precision (both before and after the decimal point), mimicking the way human clerks work with numbers. There are even regulations for this: in my country (Czech Republic), the law requires/suggests (IANAL) you to compute money-related operations (interest, fees, ...) with four decimal digit precision and then round the final number to two decimal digits.

This contrasts with floating point operations, that don't have fixed precision and cannot represent some values precisely. For example, subtracting 0.01 from a large number may yield the same number, which may be acceptable in physics simulation, but is not acceptable in finance.

code of conduct - report abuse