bbs.ChinaUnix.net
首页 | 新闻 | Linux | FreeBSD | AIX | Windows | 博客 | 论坛 | 存储 | 网络 | 人才 | Wiki | 资料 | 读书 | 手册 | 下载 | 空间 | 搜索
  免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 


[保留] 关于bc命令保留小数两位的问题?

  首页 » 论坛 » Shell »
[打印] [收藏] [本帖文本页] [推荐此主题给朋友]

这是我作的实验,为什么只有做除法运算的时候才保留两位? :?:
显示两位:
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
   
谢谢啦



关于bc命令保留小数两位的问题?

???

而且对求幂还有内置的函数运算,也起作用。
__________________________________
http://bang5.com/



关于bc命令保留小数两位的问题?

[quote]原帖由 "bjgirl"][/quote 发表:
     从来没有注意过这玩意,经你一说还真是个问题,查手册也找不到答案!



关于bc命令保留小数两位的问题?

噢!找到了,联机手册上就有!且看:
  1.   Addition, subtraction
  2.           The scale of the result is the larger of the scales of the two
  3.           operands. There is never any truncation of the result.

  4.   Multiplication
  5.           The scale of the result is never less than the maximum of the two
  6.           scales of the operands, and never more than the sum of the scales
  7.           of the operands, and subject to those two restrictions, the scale
  8.           of the result is set equal to the contents of the internal
  9.           quantity, scale.

  10.   Division
  11.           The scale of a quotient is the contents of the internal quantity,
  12.           scale.

  13.   Modulo  The scale of a remainder is the sum of the scales of the quotient
  14.           and the divisor.

  15.   Exponentiation
  16.           The result of an exponentiation is scaled as if the implied
  17.           multiplications were performed. An exponent must be an integer.

  18.   Square Root
  19.           The scale of a square root is set to the maximum of the scale of the
  20.           argument and the contents of scale.

  21.   All of the internal operations are actually carried out in terms of
  22.   integers, with digits being discarded when necessary. In every case where
  23.   digits are discarded truncation is performed without rounding.

  24.   The contents of scale must be no greater than 99 and no less than 0. It is
  25.   initially set to 0.
复制代码
   

看来scale是要区分不同情况的!



关于bc命令保留小数两位的问题?

Great! 3Q very much!  :D
__________________________________
http://bang5.com/



关于bc命令保留小数两位的问题?



QUOTE:
原帖由 "admirer" 发表:
   

看来scale是要区分不同情况的!

   
谢谢版主GG,唉,好后悔当初没有好好学习E文呀~~~ ;)



关于bc命令保留小数两位的问题?



QUOTE:
原帖由 "admirer" 发表:
   

看来scale是要区分不同情况的!

   


说的啥意思呀。。。
__________________________________
诸行无常。一切皆苦。诸法无我。寂灭为乐。



关于bc命令保留小数两位的问题?



QUOTE:
原帖由 "bjgirl" 发表:
   
谢谢版主GG,唉,好后悔当初没有好好学习E文呀~~~ ;)


点击这里帮你翻译   
至于翻译的水平嘛,嗯...跟我差不多,实在不敢恭维,只能将就着用了! :)



关于bc命令保留小数两位的问题?



QUOTE:
  加法,减法结果的标度是大的二个操作数的标度。 有从未结果的任一截。
  增殖结果的标度比操作数的二个标度的最大值比操作数的标度的总和从未是较少,和从未更多,并且依于那些二个制约,结果的标度被设置相等与内部数量的内容,标度。
  分部商数的标度是内部数量的内容,标度。
  模数剩下的人的标度是商数和除数的标度的总和。
  取幂取幂的结果被称好象含蓄的增殖执行了。 方次数必须是整数。
  方根一个方根的标度被设置对论据和标度内容的标度的最大值。
  所有内部操作实际上被执行根据整数,与数字被放弃如果必要。 数字被放弃的地方截每次执行没有环绕。
  标度内容必须是没有大于99 和没有少于0 。 它最初被设置到0 。


  这就是那玩意的翻译结果,更加云里雾里去了...



关于bc命令保留小数两位的问题?

[quote]原帖由 "Minsic"][/quote 发表:
  
加法,减法结果的标度(精度)是大的二个操作数的标度(两个操作数中的精度最高者)。 有从未结果的任一截(不会自动截取数位)。
  增殖(乘法)结果的标度比操作数的二个标度的最大值比操作数的标度的总和从未是较少(不会比两个操作数的精度小),和从未更多,并且依于那些二个制约,结果的标度被设置相等与内部数量的内容,标度。
  分部商数(除法)的标度是内部数量的内容,标度(由scale确定)。
  模数剩下的人的(求模)标度是商数和除数的标度的总和(是两个操作数的精度和)。
  取幂(幂)取幂的结果被称好象含蓄的增殖执行了(隐含按乘法规则执行)。 方次数必须是整数。
  方根一个方根的标度被设置对论据和标度内容的标度的最大值。
  所有内部操作实际上被执行根据整数,与数字被放弃如果必要。 数字被放弃的地方截每次执行没有环绕。
  标度(精度)内容必须是没有()大于99 和没有少于(不小于)0 。 它最初被设置到(初值为)0 。


  首页 » 论坛 » Shell »
Copyright © 2001-2010 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - ChinaUnix - Archiver - WAP - TOP

GMT+8, 2010-02-09 08:33, Processed in 0.028795 second(s), 8 queries, Gzip enabled.