加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

你如何在Perl中舍入一个浮点数?

发布时间:2020-12-15 21:29:53 所属栏目:大数据 来源:网络整理
导读:如何舍入十进制数(浮点)到最接近的整数? 例如 1.2 = 11.7 = 2 解决方法 输出为 perldoc -q round Does Perl have a round() function? What about ceil() and floor()? Trig functions? Remember that 07001 merely truncates toward 0 . For rounding to a
如何舍入十进制数(浮点)到最接近的整数?

例如

1.2 = 1
1.7 = 2

解决方法

输出为 perldoc -q round

Does Perl have a round() function? What about ceil() and floor()?
Trig functions?

Remember that 07001 merely truncates toward 0. For rounding to a certain number of digits,07002 or 07003 is usually the easiest
route.

06000

The 07004 module (part of the standard Perl distribution) implements
ceil(),floor(),and a number of other mathematical and trigonometric
functions.

06001

In 5.000 to 5.003 perls,trigonometry was done in the 07005
module. With 5.004,the 07006 module (part of the standard Perl
distribution) implements the trigonometric functions. Internally it
uses the 07005 module and some functions can break out from the
real axis into the complex plane,for example the inverse sine of 2.

Rounding in financial applications can have serious implications,and
the rounding method used should be specified precisely. In these
cases,it probably pays not to trust whichever system rounding is being
used by Perl,but to instead implement the rounding function you need
yourself.

To see why,notice how you’ll still have an issue on half-way-point
alternation:

06002

Don’t blame Perl. It’s the same as in C. IEEE says we have to do
this. Perl numbers whose absolute values are integers under 2**31 (on 32 bit machines) will work pretty much like mathematical integers. Other numbers are not guaranteed.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读