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

标签 linux bash

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

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

但它无法工作。

我正在寻找输出,

0.00
0.10
0.20
...

最佳答案

file format notation 中的

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.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/

相关文章:

linux - 当密码包含反引号时 bash 脚本失败

linux - 哪些 ncurses 框架可用于 BASH?

python - 使用 OpenShift 进行公共(public)客户端应用程序端口转发

c - 编译 linux 内核时无法识别 list_head

linux - 在安装 HDFS 时获取 "mount.nfs: mount system call failed"

bash - rsync --include 选项不排除其他文件

bash - 在 Bash 命令行中,如何在光标后立即剪切单词?

bash - 意外 token 'fi'

bash - curl : (3) URL using bad/illegal format or missing URL

ruby - 使用 Ruby FileUtils 而不是 Bash 命令的好处?