-2

In the symfony framework you can set scale value but that will cause symfony to round it for you after the scale. is there a way to trigger an exception if the length is > 5 for instance instead? Below code will only round the float to a scale of 5, and I'd like to know how throw an exception if it's more than 5 instead.

$builder
        ->add('amount', NumberType::class, [
            'mapped' => false,
            'required'   => false,
            'scale' => 5,
        ])
user3610279
  • 71
  • 1
  • 8
  • I'm not sure I understood the issue. You want to prevent someone from defining a scale greater than 5 inside the code? – El_Vanja Feb 23 '21 at 11:39
  • No, for a form, I want to allow 5.12345 but not allow 5.123456, the first one has a scale of 5, but i want anything more than scale of 5 to throw an exception. so basically i just want to limit the number of digits after the decimal place to 5 for the user input – user3610279 Feb 24 '21 at 05:48
  • Write a custom validator and [check manually](https://stackoverflow.com/questions/2430084/php-get-number-of-decimal-digits). – El_Vanja Feb 24 '21 at 08:46

1 Answers1

-1

You can use Symfony validation on your field 'amount' to verify the scale when submitted.