Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#!/usr/bin/perl $test = 1.30733; $test = int($test * 100000); print "test : " , $test ;
测试结果:130732
有人能告诉我为什么吗?
130733/100000 是二进制的周期数,就像 1/3 是十进制的周期数一样。将其存储为浮点数需要无限的存储空间。
它实际上存储了比 130733/100000 少一点的东西。
输出浮点数时始终使用舍入,比较它们时始终使用容差。
如果你跳过 int() Perl 会在这里 DWIM:
> $x * 100000 130733