A real fixed-point decimal crate in Rust
a year ago
- #Rust
- #fixed-point
- #decimal
- Rust's built-in f32 and f64 types have drawbacks: they can't accurately represent decimal numbers in base 10 and don't guarantee fraction precision.
- This crate provides fixed-point decimal types using integer types with a scaling factor in base 10 for accuracy and static scale binding for precision.
- Two types of fixed-point decimals are offered: ConstScaleFpdec (scale specified via const generics) and OobScaleFpdec (scale managed out-of-band).
- Operations like +, -, and comparisons are restricted to same types and scales, ensuring type safety and performance, while * and / allow different scales with specified result scales.
- The crate addresses cumulative error in operations like transaction fees through a cum_error parameter, improving precision in financial calculations.
- Supports no_std and optional serde integration for serialization/deserialization.
- License: MIT.