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

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -