I can't figure out how to use seq to pad decimal places. Here is what I tried based on what i found online...
for U in $(seq -f "%0.2g" 0 0.1 1)
but it fails to work.
I am looking to get the output,
0.00
0.10
0.20
...
g
in the file format notation removes trailing zeros. You want f
:
seq -f "%0.2f" 0 0.1 1
resulting in
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
The relevant excerpts from the spec are these:
f
,F
The floating-point number argument shall be written in decimal notation in the style [-] ddd . ddd , where the number of digits after the radix character (shown here as a decimal point) shall be equal to the precision specification.
e
,E
The floating-point number argument shall be written in the style [-] d . ddd e± dd (the symbol '±' indicates either a <plus-sign> or minus-sign), where there is one digit before the radix character (shown here as a decimal point) and the number of digits after it is equal to the precision.
g
,G
The floating-point number argument shall be written in style
f
ore
(or in styleF
orE
in the case of aG
conversion specifier), with the precision specifying the number of significant digits. [...] Trailing zeros are removed from the result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.