Linux bc add 0 before the decimal point




One, bc lacks 0 problem


bc is a powerful and commonly used calculation tool,
but when doing division operations, if the result value is less than 1, the 0 before the decimal is missing:

echo "scale=2;2/3"|bc
.66
//注意这里必须带 scale ,否则输出为 0 。



Two, simple complement 0 method


echo $(printf "%.2f" `echo "scale=2;1/3"|bc`)
0.66



Guess you like

Origin blog.csdn.net/weixin_44648216/article/details/113850986