symfony icon indicating copy to clipboard operation
symfony copied to clipboard

Not possible to deactivate rounding in `PercentToLocalizedStringTransformer`

Open floriansemm opened this issue 1 year ago • 2 comments

Symfony version(s) affected

6.3

Description

In previous versions $roundingMode was a nullable constructor argument/class-property. This has changed to a int argument with default value \NumberFormatter::ROUND_HALFUP.

This means all not null checks in Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer like this are useless and a rounding is always set and not possible to "disable" it.

My local fix is a transformer that extends this class and overwrites getNumberFormatter, but I don't think that it supposed to be the way to go to disable rounding.

How to reproduce

Create an instance of PercentToLocalizedStringTransformer and transform values like 1.23 which should result in a 0.0123 number.

I am using the transformer as view-transformer for a custom percentage form-type. So in my case input like 1.23 should transformed to 1,23 which worked perfectly in SF 5.4.

Possible Solution

Make property nullable again.

Additional Context

No response

floriansemm avatar Nov 10 '23 09:11 floriansemm