在bash我可以使用printf
格式化像这样的字符串输出: - (请注意我是如何加的W
后缀的字符串,这是不包括在填充)猛砸printf的前缀
$ printf "Blah %11.1fW\n" 123 456 78965 5 56
Blah 123.0W
Blah 456.0W
Blah 78965.0W
Blah 5.0W
Blah 56.0W
如果我想前缀字符串我可以这样做: -
$ printf "Blah £%11.1f\n" 123 456 78965 5 56
Blah £ 123.0
Blah £ 456.0
Blah £ 78965.0
Blah £ 5.0
Blah £ 56.0
但是请注意这是如何导致填充前缀之前被应用。
如何(如果可能的话)我会用printf
填充之前的前缀值,使输出将如下所示: -
Blah £ 123.0
Blah £ 456.0
Blah £ 78965.0
Blah £ 5.0
Blah £ 56.0
如果没有任何可能的解决方案的Bash将是适当的。
会计师对此感到满意吗?根据我的经验,'printf'风格四舍五入导致会计师晕倒。 – cdarke 2012-07-05 10:47:30
@cdarke大声笑。这只是一个例子。没有会计师参与! – 2012-07-05 10:51:29