Skip to content

Choosing a Type for Money

Question

Which type would you use to store a monetary value?

Short interview answer

Usually decimal, because it has base-10 precision suitable for financial calculations. Store the currency separately when the domain supports multiple currencies.

Detailed answer

Binary floating-point values such as double cannot represent many decimal fractions exactly, which can produce surprising rounding results. decimal is designed for financial and monetary calculations, but it is not a complete money model: specify currency, rounding rules, scale, and whether amounts are net, gross, or tax-inclusive.

Sources