How can I format the number for only showing 1 decimal place in php?

You use the round function

echo round(3.4445, 1); // 3.4

Number format will do this for you.

$num = 2.10;
number_format($num, 1);

PHP: number_format


Use PHP's number_format

http://php.net/manual/en/function.number-format.php

Example:

$one_decimal_place = number_format(2.10, 1);

If you ever need to convert it back to a float:

$the_float_value = floatval($one_decimal_place);

Also, this article is a good reference for different decimal characters and separator styles.

Tags:

Php