mysql - PHP number_format returns 1.00 -


i have stored in mysql number total(decimal 16,2) 1423.28

i display php after making calculations:

function calculate_balance($total){   //get total paid function  $total_paid = ...   if ($total_paid == 0){      return $total;  }else{      return $total-$total_paid  }  }    $balance = calculate_balance($total);  echo number_format($balance, 2); //returns 1.00 

i have tried

  number_format((float)$balance, 2);   number_format(floatval($balance), 2);  

update

var_dump($balance)

and got following output.

string(8) "1,423.28" float(152) string(6) "252.00" string(6) "247.50" string(6) "247.50" string(6) "247.50" string(6) "549.90" string(6) "495.00" float(0) string(6) "284.76" float(265)

it's working fine without number_format() value under 1,000. e.g.: if balance equal 252.00

 echo $balance; 

output

252.00

your function returns 1,423.28? not float, float never contain comma thousands-separator.

php interprets 1, because "breaks" @ comma.

remove comma , fine!

$balance = str_replace(',', '', $balance); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -