Fixed-precision decimal values for financial and high-precision computations
A Decimal in Internet Object represents fixed-precision decimal values designed for applications that require exact numeric calculations, especially financial computations where floating-point precision issues could lead to significant errors. Decimal is a scalar primitive that stores exact numeric values with a defined precision and scale.
Unlike standard floating-point numbers (which may suffer from approximation issues), Decimal values maintain exact precision throughout arithmetic operations, ensuring accurate and predictable results.
Syntax
A Decimal value is expressed as a number with the m suffix:
123.45 # ❌ Missing 'm' suffix (should be 123.45m)
123.45mm # ❌ Multiple suffixes not allowed (should be 123.45m)
m123.45 # ❌ Suffix must be at the end (should be 123.45m)
.45m # ❌ Must have leading digit (should be 0.45m)
123.m # ❌ Must have trailing digit if decimal point used (should be 123.0m or 123m)