Skip to content

NumberToLocalizedStringTransformer alters big integers #60947

Open
@mhbailly

Description

@mhbailly

Symfony version(s) affected

7.3

Description

Description
When a big int (still < PHP_INT_MAX) is processed by round(int|float $number) in NumberToLocalizedStringTransformer, its value is altered (loss of precision).

I.e.: round(760934254250171757) --> 760934254250171776

Affects Symfony 7.3 and before

How to reproduce

Details here : EasyCorp/EasyAdminBundle#6934

Possible Solution

Add a type check at the beginning of the method. Integers don't need to be rounded.

private function round(int|float $number): int|float
{
    if (is_int($number)) {
        return $number;
    }
    
    // ...
}

fix-bigint-rounding.patch

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions