Skip to content

Problem with casting into (int) or intval() #8028

@VILQ

Description

@VILQ

Description

The following code:

<?php
$a = 42.85 * 100 - 34.84 * 100;
$b = (int)$a;
$c = (int)round($a);

echo $a."\n".$b."\n".$c;

Resulted in this output:

801
800
801

But I expected this output instead:

801
801
801

The result is consistent when we change '34.84' to e.g. '34.85', '34.86' or '34.83'.
Eval link: https://3v4l.org/geEpE

When $b = intval($a) the result is the same.

PHP Version

8.0.22

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions