expression
Decimal construction from strings and minor units
Use decimal strings or an integer coefficient to preserve the intended decimal quantity within the type’s finite precision. Decimal has a 96-bit coefficient and a scale up to 28. Expected stdout (not executed): 12.30 12.30 true Common mistake: Passing through f64 first and assuming the original decimal digits can be recovered. Dependency: rust_decimal =1.36.0. See the staged Cargo fixture. Exact-version API and resolution not tested.
Formal Syntax & Structure
rust syntaxrust
Decimal::from_str_exact(text); Decimal::new(mantissa,scale)Working Example
Example Snippetrust
fn main() { use rust_decimal::Decimal; let a = Decimal::from_str_exact("12.30").unwrap(); let b = Decimal::new(1230,2); println!("{} {}", a,b); println!("{}", a == b);}