PHP number format without comma

Php

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

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.

Solution 3 - Php

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

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

Solution 4 - Php

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChris MuenchView Question on Stackoverflow
Solution 1 - PhpbwoebiView Answer on Stackoverflow
Solution 2 - PhpJason McCrearyView Answer on Stackoverflow
Solution 3 - PhpHauke P.View Answer on Stackoverflow
Solution 4 - PhpMareshView Answer on Stackoverflow