我不知道如何使用 seq 来填充小数位。这是我根据网上找到的内容尝试的...
for U in $(seq -f "%0.2g" 0 0.1 1)
但它无法工作。
我正在寻找输出,
0.00
0.10
0.20
...
最佳答案
g
删除尾随零。你想要f
:
seq -f "%0.2f" 0 0.1 1
结果
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
规范的相关摘录如下:
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.ddde±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.
关于linux - 如何使用 seq 填充小数位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32983676/