linux下的bc命令可以设置结果的位数,通过 scale.
比如:
$ echo “scale=4; 1.2323293128 / 1.1” | bc -l
1.1202
但是scale只对除法、取余、乘幂有效,比如乘法就无效:
$ echo “scale=4; 1.2323293128 * 1.1” | bc -l
1.3555622440
想了一个回避的方法,就是除以1。
比如:
$ echo “scale=4; (1.2323293128 * 1.1) / 1” | bc -l
1.3555
root@host109:/opt# echo “scale=0; l b a n u m 1 0 ∗ {lba_num_10}* lbanum10∗{t_rate}”|bc
7501465944.0
root@host109:/opt# echo “scale=1; l b a n u m 1 0 ∗ {lba_num_10}* lbanum10∗{t_rate}”|bc
7501465944.0
root@host109:/opt# echo “scale=2; l b a n u m 1 0 ∗ {lba_num_10}* lbanum10∗{t_rate}”|bc
7501465944.0
root@host109:/opt# echo “scale=2;KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 52: …ot@host109:/opt#̲ echo “scale=2;…{lba_num_10}”|bc
7501465944.0
root@host109:/opt# echo “scale=0;0.5*KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 48: …ot@host109:/opt#̲ echo “scale=0;…{lba_num_10}”
scale=0;0.515002931888
root@host109:/opt# echo “scale=0;0.5KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 50: …ot@host109:/opt#̲ echo “scale=0;{lba_num_10}*${t_rate}/1″|bc
7501465944
root@host109:/opt#