3 ms·
The Haskell library safe-money does a great job of handling these weird cases for currencies. It has a separation between the types used for calculations and st
by axman6 7y ago
The Haskell library safe-money does a great job of handling these weird cases for currencies. It has a separation between the types used for calculations and storage/presentation, and lets you define arbitrary ones so in your example you can handle computations in an arbitrary precision rational representation and then store it in cents and later convert with proper rounding to 5 cent increments if necessary. Much of this is handled by the type system, including type safe currency conversion.