Precise Decimal Fixed-Point Types in Rust: primitive_fixed_point_decimal

2025-06-20
Precise Decimal Fixed-Point Types in Rust: primitive_fixed_point_decimal

Rust's built-in floating-point types lack precision when representing decimal numbers. The `primitive_fixed_point_decimal` crate offers a solution by using integer types and a scaling factor to represent decimals accurately, guaranteeing fractional precision. It provides two types: `ConstScaleFpdec`, which specifies the scaling factor at compile time; and `OobScaleFpdec`, which allows specifying it at runtime, offering greater flexibility but increased complexity. The crate also addresses cumulative errors from multiple multiplications and divisions, providing a `cum_error` mechanism for control. In short, it's an efficient and precise Rust library for decimal fixed-point types, ideal for applications demanding high accuracy, such as financial systems.

Development fixed-point decimal