没有逗号的PHP数字格式

I want to display the number 1000.5 like 1000.50 with 2 decimal places and no commas/thousands separators.

I am using number_format to achieve this:

number_format(1000.5, 2);

This results 1,000.50. The comma (,) separator appended in thousand place which is not required in the result.

How can I display the number with a trailing zero and no comma?

See the documentation for number_format: http://php.net/number_format

The functions parameters are:

string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

So use:

number_format(1000.5, 2, '.', '');

Which means that you don't use any (= empty string) thousands separator, only a decimal point.

number_format() takes additional parameters:

number_format(1000.5, 2, '.', '');

The default is a period (.) for the decimal separator and a comma (,) for the thousands separator. I'd encourage you to read the documentation.

number_format(1000.5, 2, '.', '');

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

The documentation of number_format contains information about the parameter string $thousands_sep = ','. So this should work:

number_format(1000.5, 2, '.', '');

Hi You can also use the below code to remove the comma from the number

<?php
$my_number = number_format(1000.5, 2);
echo str_replace(',', '', $my_number);
?>