bash的浮点精度 [英] floating point accuracy with bash
本文介绍了bash的浮点精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
DIFF=$(( ($END - $START) / 60 ))
echo "Build took $DIFF minutes"
我1:30分钟的输出是:
My output for 1:30 minutes is:
Build took 1 minutes
如何在此处使用浮点数,这样我的输出将是:
How do I employ floating point here so that my output will be:
Build took 1.50 minutes
推荐答案
使用bc获得精度
示例:
kent$ echo "scale=2;(190-100)/60"|bc
1.50
用变量替换硬编码的数字.
replace hardcoded number with your variables.
这篇关于bash的浮点精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文