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}", ¢s / 100, ¢s % 100)
}
}
|