Rounding decimal numbers in perl, wrong result

前端 未结 2 731
执念已碎
执念已碎 2021-01-03 10:05

I hate decimal numbers. For 1.005 I don\'t get the result I expect with the following code.

#!/usr/bin/perl -w

use strict;
use POSIX qw(floor);

my $num = (         


        
2条回答
  •  暖寄归人
    2021-01-03 10:32

    floor() is not for rounding, it goes down to the nearest integer.

    See this old post: How do you round a floating point number in Perl?

提交回复
热议问题