Back 0 Comments

How to Show Only One Decimal Place for a Number in PHP Without Rounding Up

This is one way to display a number in PHP without rounding up.  number_format() would round the number up, so I've used substr() to simply 'hide' the extra decimal places.


$number = "20.58";
$number = substr($number,0,strpos($number,".") + 2);

echo $number;


Your comment has been posted....