Craft 3 is giving me this error when my client enters non-numeric characters into a number field on an entry:

number_format() expects parameter 1 to be float, string given

Is there a way for it to check and remove non-numeric characters from the field on save? Or maybe my setup is incorrect?

  • Is it an error or an exception? Because it actually should display errors rather than removing the characters. You could create a custom field that strips all letters from the input Oct 31, 2018 at 15:22
  • Per an image my client sent: PHP Warning - yii\base\ErrorException Oct 31, 2018 at 15:25
  • Shouldn't craft handle this natively? Either not allowing non-numeric characters in number fields or something? Oct 31, 2018 at 15:26

1 Answer 1


Just tested this on a local Craft3 setup and here's what I discovered...

If the decimal points setting on the number field is set to 0, adding text in the number field will display the pretty errors below:

enter image description here

If the decimal points setting is set to anything else, you get the Twig error mentioned in the title of this post:

number_format() expects parameter 1 to be float, string given

I'd recommend opening an issue in the Craft CMS repo as I imagine the number field ought to display the pretty errors no matter if decimal points is set or not.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.