expression

Decimal explicit midpoint strategies

Choose the scale and midpoint policy explicitly. Half-even and ties away from zero can differ on the same exact decimal amount. Expected stdout (not executed): 1.02 1.03 Common mistake: Assuming every business domain requires the same rounding policy. Dependency: rust_decimal =1.36.0. See the staged Cargo fixture. Exact-version API and resolution not tested.

Formal Syntax & Structure

rust syntaxrust
d.round_dp_with_strategy(dp, RoundingStrategy::MidpointNearestEven)

Working Example

Example Snippetrust
fn main() {    use rust_decimal::{Decimal,RoundingStrategy};    let d=Decimal::new(1025,3);    println!("{} {}",d.round_dp_with_strategy(2,RoundingStrategy::MidpointNearestEven),d.round_dp_with_strategy(2,RoundingStrategy::MidpointAwayFromZero));}
Rust Reference