I'd like to know if exists some function to automatically format a number by it's decimal, so if I have:
<?php
// $sql_result["col_number"] == 1,455.75
number_format ($sql_result["col_number"], 2, ".", "");
// will return 1455.75
// $sql_result["col_number"] == 1,455.00
number_format ($sql_result["col_number"], 2, ".", "");
// could I get 1455 instead of 1455.00?
?>
so my answer is if does exist some way to remove the decimals if I have DECIMAL data forma in my DB only when it's round?
Or shoud I do something like that?
<?php
// $sql_result["col_number"] == 1,455.00
str_replace(".00", "", (string)number_format ($sql_result["col_number"], 2, ".", ""));
// will return 1455
?>
Warren.S answer helped me out. I didn't need the number_format function, so I just did this
But in the OP's case, he needs number_format to remove the commas. So this would work for him
floatval or simply casting to float
Actually I think the cleanest way I can think of to do this for someone that just did a search looking for this sort of thing is to do this:
Since I could not find a flexible solution I wrote a simple function to get the best result:
If you are targeting US currency I like to use this method: