expression

Reject invalid or unrepresentable decimal text

Parse exact text at an application boundary. Syntax errors and nonrepresentable fractional precision must not silently become zero. Apply separate domain-specific scale and range checks. Expected stdout (not executed): true true true Common mistake: Treating every parseable decimal as a valid amount for a particular currency. 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) -> Result<Decimal, Error>

Working Example

Example Snippetrust
fn main() {    use rust_decimal::Decimal;    println!("{}",Decimal::from_str_exact("0.001").is_ok());    println!("{}",Decimal::from_str_exact("invalid").is_err());    let tiny = format!("0.{}1", "0".repeat(28));    println!("{}",Decimal::from_str_exact(&tiny).is_err());}
Rust Reference