Rust library: fraction_list_fmt_align
Formats a list of arbitrary fractional numbers (either string or f32/f64) so that they are correctly aligned when printed line by line. It also removes unnecessary zeroes. This means that it rather returns "7" instead of "7.000000".
Input
a) either a list of formatted fractional number strings
b) or a list of f32/f64
Example
# Input
"-42"
"0.3214"
"1000"
"-1000.2"
"2.00000"
# Output
" -42 "
" 0.3214"
" 1000 "
"-1000.2 "
" 2 "
Use case
If you want to write multiple fraction numbers of different lengths to the terminal or a file in an aligned/formatted way.
Difference to std::fmt
- This is more flexible than
println!()/format!()
because it adjusts to a dynamic precision over multiple lines. - This removes unnecessary zeroes, i.e. "0.000" will become "0"
How to use
use ;
MSRV
The MSRV is 1.56.1
.