[英]How to pad decimal places using seq
I can't figure out how to use seq to pad decimal places. 我无法弄清楚如何使用seq填充小数位。 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. g
以文件格式表示法删除尾随零。 You want f
: 你想要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
f
,F
The floating-point number argument shall be written in decimal notation in the style [-] ddd . 浮点数参数应以样式[ - ] ddd的十进制表示法写入。 ddd , where the number of digits after the radix character (shown here as a decimal point) shall be equal to the precision specification. ddd ,其中基数字符后面的位数(此处显示为小数点)应等于精度规格。
e
,E
e
,E
The floating-point number argument shall be written in the style [-] d . 浮点数参数应以样式[ - ] 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. ddd e± dd (符号'±'表示<加号>或减号),其中基数字符前面有一个数字(此处显示为小数点),后面的数字相等精确度。
g
,G
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. 浮点数参数应以样式f
或e
(或在G
转换说明符的情况下以F
或E
形式)写入,精度指定有效位数。 [...] Trailing zeros are removed from the result. [...] 从结果中删除尾随零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.