gpt4 book ai didi

linux - 如何使用seq填充小数位

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:50:35 24 4
gpt4 key购买 nike

我不知道如何使用 seq 来填充小数位。这是我根据在网上找到的内容尝试的...

for U in $(seq -f "%0.2g" 0 0.1 1)

但它无法工作。

我正在寻找输出,

0.00
0.10
0.20
...

最佳答案

gfile format notation删除尾随零。你想要 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.ddddd (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 or e (or in style F or E in the case of a G 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com