我如何获得BC(1)打印前导零? [英] How do I get bc(1) to print the leading zero?

查看:132
本文介绍了我如何获得BC(1)打印前导零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做这样的事情在一个Makefile如下:

I do something like the following in a Makefile:

echo "0.1 + 0.1" | bc

(在真实的文件的数量是动态的,当然)

(in the real file the numbers are dynamic, of course)

它打印 0.2 ,但我想它来打印 0.2

It prints .2 but I want it to print 0.2.

我想做到这一点,而不诉诸 SED 但我似乎无法找到如何获得 BC 打印为零。或者是 BC 只是没能做到这一点?

I would like to do this without resorting to sed but I can't seem to find how to get bc to print the zero. Or is bc just not able to do this?

推荐答案

您也可以诉诸awk将格式为:

You can also resort to awk to format:

 echo "0.1 + 0.1" | bc | awk '{printf "%f", $0}'

或使用awk本身做数学:

or with awk itself doing the math:

 echo "0.1 0.1" | awk '{printf "%f", $1 + $2}'

这篇关于我如何获得BC(1)打印前导零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆