mercredi 5 avril 2017

Stop giving error number_format for PHP

Here is question:

$var = 1000;
$var2 = number_format($var,2);// No error

And;

$var = 'Some String';
$var2 = number_format($var,2);// Gives 'number_format() expects parameter 1 to be double.... error'

My handling solution is;

$var = 'Some String';
$var_escape = 1000;
if(!$var2 = number_format($var,2)){
    $var2 = $var_escape;// if $var not a integer; always give 1000 to $var2.
}

This solution working perfectly but; still giving "expect parameter error"; because of this line:

if(!$var2 = number_format($var,2)){

I don't want to use "@" supression. Is there any other solution for this issue? Thanks...

Aucun commentaire:

Enregistrer un commentaire