What format string should I use in the println!
macro in order to print 0.0
as 00000.000
?
println!("={:05.3}", 0.0);
Output: =0.000
Expected: =00000.000
pub fn powi(self, n: i32) -> f32Raises a number to an integer power. Using this function is generally faster than using powf .
pub fn round(self) -> f64 Returns the nearest integer to self . Round half-way cases away from 0.0 .
Creates a String using interpolation of runtime expressions.
The first number (after the zero) is the total number of characters.
So you do display your number with 5 characters. If you want to have 5 numbers before the dot, you must type:
println!("{:09.3}", 123.45);
Output: 00123.450
Because 9 minus 3 minus the dot = 5 digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With