这是我作的实验,为什么只有做除法运算的时候才保留两位? :?:
显示两位:
echo "scale=2;1234.333"|bc
1234.333
加法:
echo "scale=2;1234+1.999"|bc
1235.999
减法:
echo "scale=2;1234-334.999"|bc
899.001
乘法:
echo "scale=2;1234.333"|bc
1234.333
echo "scale=2;1234*12.3333"|bc
15219.2922
除法:
echo "scale=2;1234/12.333"|bc
100.05
可以看出指定了scale,那为什么scale只在除法中起作用了呢?
think过没呢?
search过没呢?
do过没呢?
see过没呢?
下面是bc的部分文档,just see see吧.总算整完shell了,开始看DS
Addition, subtraction
The scale of the result is the larger of the scales of the two
operands. There is never any truncation of the result.
Multiplication
The scale of the result is never less than the maximum of the two
scales of the operands, and never more than the sum of the scales
of the operands, and subject to those two restrictions, the scale
of the result is set equal to the contents of the internal
quantity, scale.
Division
The scale of a quotient is the contents of the internal quantity,
scale.
Modulo The scale of a remainder is the sum of the scales of the quotient
and the divisor.
Exponentiation
The result of an exponentiation is scaled as if the implied
multiplications were performed. An exponent must be an integer.
Square Root
The scale of a square root is set to the maximum of the scale of the
argument and the contents of scale.
All of the internal operations are actually carried out in terms of
integers, with digits being discarded when necessary. In every case where
digits are discarded truncation is performed without rounding.
The contents of scale must be no greater than 99 and no less than 0. It is
initially set to 0.
|
阅读(6510) | 评论(0) | 转发(0) |