rust_number
rust_number is a Rust port of number-precision for safer decimal arithmetic with f64.
It helps avoid common floating-point surprises such as:
0.1 + 0.2 != 0.3
1.0 - 0.9 != 0.1
3.0 * 0.3 != 0.9
Features
- Corrects common precision issues for addition, subtraction, multiplication, division, and rounding
- Supports decimal strings and scientific notation
- Exposes helper utilities like
strip,digit_length, andfloat2fixed - Includes iterator-based helpers for multi-value operations
Installation
Add this crate to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
Run the example locally:
API
strip(num, precision) -> f64digit_length(num) -> u32float2fixed(num) -> i128plus(a, b) -> f64minus(a, b) -> f64times(a, b) -> f64divide(a, b) -> f64round(num, decimal) -> f64plus_all(values) -> f64minus_all(values) -> f64times_all(values) -> f64divide_all(values) -> f64enable_boundary_checking(enabled)
All numeric APIs accept:
- integer types
f32/f64&strString
Multi-Value Operations
use ;
Scientific Notation
use ;
Testing
License
MIT