Reputation: 9
Is there a way to format 0s as blanks in php? I know how to change the format of positive and negative values but not 0s, using something like this:
$final = number_format($number,2);
Upvotes: 1
Views: 32
Reputation: 59681
This should work for you:
<?php
$number = 3.12;
if (substr(number_format($number,2), -2) == 0)
$final = $number;
else
$final = number_format($number,2);
echo $final;
?>
Input/ Output:
//number = 3.00
//Output = 3
//number = 3.12
//output = 3.12
Upvotes: 0