user6660680
user6660680

Reputation:

Format number with dot instead of comma as thousand separator

If I use number_format to format a number like this:

$price = 1500;
echo number_format($price);

Then I get output like this: 1,500

How can I make the thousands separator be a dot instead of a comma (i.e. get 1.500 as my output instead)?

Upvotes: 0

Views: 3360

Answers (1)

Mark Amery
Mark Amery

Reputation: 154725

The third and fourth arguments of number_format control the characters used for the decimal point and the thousands separator, respectively. So you can just do this:

number_format(
    1500,
    0, // number of decimal places
    ',', // character to use as decimal point
    '.' // character to use as thousands separator
)

and get "1.500" as your result.

Upvotes: 3

Related Questions