Hello:
Does any one know how I can format 4.0 to say 4 but yet if I had 4.5 it would stay the same? Basically I guess I just don't want .0 to show up
Any help would be great
This code works:
$number = 4.35;
$split = explode('.',$number); if($split[1] == 0) { $number = $split[0]; } else { $number = $number; }
echo $number;
try using number as a float value and then as 4.0, for testing.. hope that will do the trick.
Thanks! That did the trick!
You can remove the else portion of that code. Why waste any processor cycles to set $number equal to itself?
Then again
$number=4.0; echo $number;
tends to work for me.
If you mean that $number is a string, then
$number='4.0'; $number = floatval($number); echo $number;
or even
$number='4.0'; $number = 0+$number; echo $number;