php - number_format only if not zero
333
I want to show one decimal of a float if it has non zero decimals.
What is the most elegant way to do this?
100.00 -> 100
99.45 -> 99.5
99.44 -> 99.4
11.30 -> 11.3
2.00 -> 2
11.02 -> 11
13.05 -> 13.1
Answer
Solution:
this should do the task
Answer
Solution:
use in the following manner.
Answer
Solution:
I prefer this way:
$num = 100.1;
echo (floor($num) == $num) ? $num : number_format($num,1);
Answer
Solution:
I have tested the above with your sample data and the outputs are as follows: