php - Echo decimal value without point zero ( .0 ) at end -
i using
decimal (5,1)
to store data. when value 12.2, 66.4
... evething ok. not decimal value : 5, 10 , 20
.... when echo 5.0, 10.0
...
how can echo them :
1, 2.2, 2.5, 10, 10.5, 10.6, 11
gordon linoff's answer may trick, here php way :
echo (intval($var) == $var) ? intval($var) : $var;
or, if don't ternary conditions :
if (intval($var) == $var) { echo intval($var); } else { echo $var; }
Comments
Post a Comment