DEV Community

Discussion on: What Elm and Rust Teach us About the Future

Collapse
 
martinmodrak profile image
Martin Modrák

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.