Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我bc在 Bash 程序中使用负指数时遇到了困难。如果我执行echo "2*1.86929*10^05" | bc,我会得到一个结果,373858.00000而如果我执行echo "2*1.86929*10^-05" | bc,我只会得到一个结果0。使用负指数时如何获得更好的准确性?
bc
echo "2*1.86929*10^05" | bc
373858.00000
echo "2*1.86929*10^-05" | bc
0
默认情况下, 的输出bc四舍五入为整数。要保留结果的小数部分,请使用bc -l,如下所示:
bc -l
$ echo "2*1.86929*10^-05" | bc -l .00003738580000000000
您需要设置“比例”的值 - 所以
scale=50 2*1.86929*10^-05
给出 .000037385800000000000000000000000000000000000000000