Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make dots between numbers in php

Tags:

php

I would like to make dots between my total value.

If i have 425000 i would like it to show as 425.000

Is there a function in php that implodes dots for numbers or how can i do this then?

like image 248
Karem Avatar asked Dec 11 '25 15:12

Karem


2 Answers

Use number_format for this:

$number =  425000;
echo number_format( $number, 0, '', '.' );

The above example means: format the number, using 0 decimal places, an empty string as the decimal point (as we're not using decimal places anyway), and use . as the thousands separator.

Unless of course I misunderstood your intent, and you want to format the number as a number with 3 decimal places:

$number =  425000;
echo number_format( $number, 3, '.', '' );

The above example means: format the number, using 3 decimal places, . as the decimal point (default), and an empty string as the thousands separator (defaults to ,).

If the default thousands separator is good enough for you, you can just use 1:

$number =  425000;
echo number_format( $number, 3 );


1) Mind you: number_format accepts either 1, 2 or 4 parameters, not 3.
like image 133
Decent Dabbler Avatar answered Dec 14 '25 05:12

Decent Dabbler


I guess you're looking for the number_format function.

like image 27
Macmade Avatar answered Dec 14 '25 04:12

Macmade