Why does Perl's sprintf not round floating point numbers correctly?

前端 未结 2 1588
不思量自难忘°
不思量自难忘° 2020-12-07 02:13

I was out looking for the rounding convention used by Perl\'s built-in function sprintf.

I was thinking that it does a normal rounding (e.g. ROUND_HALF_UP as in Java

2条回答
  •  时光说笑
    2020-12-07 03:10

    This is a function of IEEE floating point numbers.

    For more information, in a Perl context, see Perlfaq4 "Does Perl have a round() function" and in particular what it says about half-way-point alternation.

提交回复
热议问题