problem with Infinity in number_format

Asked

Viewed 28 times

0

Good use of php’s number_format function, to format values in the pattern I want.

I do so:

number_format($valor_form, 2, '.', '');

The problem is that at some point the user informs a very crazy value in the form, and causes an error in the function, as it arrives a string 'Infinity'.

My question is how to check if it is a string, and if it is I have to change the value of the variable 'value_form' to 0.

Can someone help me?

  • 1

    Hello, I don’t know if it’s the right answer but try it this way: number_format($valor_form*1, 2, '.', '');

  • I didn’t quite understand what you tried to do. What I want to check is if there is a number in $valor_form

  • 2

    Multiplying a string equals 0. It also has the function is_numeric()

  • This number is integer or can have decimal?

  • well, it can be integer or decimal

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.