Currency: Difference between revisions

Content added Content deleted
(→‎{{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: Line 1,981:
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cents = (&self.amount * BigInt::from(100)).to_integer();
let cents = (&self.amount * BigInt::from(100)).to_integer();
write!(f, "${}.{}", &cents / 100, &cents % 100)
write!(f, "${}.{:0>2}", &cents / 100, &cents % 100)
}
}
}
}