Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4843082
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2008-11-04 19:42:08

这是我作的实验,为什么只有做除法运算的时候才保留两位? :?:
显示两位:
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) |
给主人留下些什么吧!~~