lIP TT lIP TT - 3 months ago 8
PHP Question

PHP return 1 number after dot in float

I have got this php code

$Likes=1112;
$Likes=$Likes/1000;
echo $Likes."k";


This code returns me 1.112k,but my goal is to get 1.1k

Answer

Use the number_format function:

echo number_format($Likes,1)."k";

And a coding style advice: don't start your variables with an upper case letter!

Comments