-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Labels
Description
Description
Parameter scale of PercentType is a bit confusing when you know how it works for the NumberType one:
NumberTypewill round the submitted value, meaning the model will be rounded too; What's saved and what's shown in the view is identical.PercentTypewill round the view only, but will save the model with all the decimals sent.
Example
Consider this form:
$form = $this
->createFormBuilder()
->add('number', NumberType::class, ['scale' => 2])
->add('percent', PercentType::class, ['type' => 'integer', 'scale' => 2])
->getForm();Then submit values with more decimals than the scale is set to and dump the model:
Something like:
$form->submit(['number' => 1.234, 'percent' => 1.234]);
dump($form->getData());The NumberType will actually round the model. The PercentType one will ignore this scale and keep every decimals in the model.
But the view will then show:
Leading to something strange, in my opinion.
Having the same behaviour for both would be great, or changing the name of this parameter in PercentType to make this difference clearer like view_scale for example.
Thanks!
cybernet, apetitpa and VincentLanglet


