Jump to content

Currency: Difference between revisions

→‎{{header|Rust}}: Correct the formatting of minor currency units (zero-padded) otherwise it prints $2.01 as $2.1
(→‎{{header|Rust}}: changing an f64 to a Currency is dangerous as the original has limited precision - need to add round() before casting to i64)
(→‎{{header|Rust}}: Correct the formatting of minor currency units (zero-padded) otherwise it prints $2.01 as $2.1)
Line 1,981:
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cents = (&self.amount * BigInt::from(100)).to_integer();
write!(f, "${}.{:0>2}", &cents / 100, &cents % 100)
}
}
47

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.