Help with number_format in following code to include 2 decimal places.

Please help. Currently an item listed as 5.50 metres is displaying as 6 metres. Please show me how to change the code below so it shows 5.50. Thank you :slight_smile:

$tmp = number_format($row[“length”],0);
if ($tmp != “0”) {$listitemyear .= “, $tmp metres”;}

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

Thanks Strider64. I read that link yesterday but my issue was how to format the code by inserting this: $english_format_number = number_format($number, 2, ‘.’, ‘’) into the following code?

$tmp = number_format($row[“length”],0);
if ($tmp != “0”) {$listitemyear .= “, $tmp metres”;}

My attempt was the following which was obviously wrong. Thanks in advance for your help.
$tmp = number_format($number, 2, ‘.’, ‘’) ($row[“length”],0);
if ($tmp != “0”) {$listitemyear .= “, $tmp metres”;}

The answer was staring straight at me - just had to replace the ‘0’ with ‘2’

			$tmp = number_format($row["length"],2);
			if ($tmp != "0") {$listitemyear .= ", $tmp metres";}
Sponsor our Newsletter | Privacy Policy | Terms of Service