How to separate numbers with commas in php?
I would like to know how can I add comma's to numbers. To make my question simple. Show I would like to change this:
To:
and :
to
and so on for larger numbers. Is it possible with a php function?
Ben 52.2k48 gold badges171 silver badges217 bronze badges asked Jan 3, 2011 at 6:49
Ahmad FouadAhmad Fouad 3,80714 gold badges44 silver badges62 bronze badges 0 from the php manual http://php.net/manual/en/function.number-format.php I'm assuming you want the english format.
my 2 cents
oldboy 5,2544 gold badges26 silver badges74 bronze badges answered Jan 3, 2011 at 6:53
0 The Following code is working for me, may be this is helpful to you.
Saty 22.3k7 gold badges30 silver badges49 bronze badges answered Aug 31, 2013 at 11:24
Kausha MehtaKausha Mehta 2,7801 gold badge19 silver badges31 bronze badges 0
answered Jul 30, 2013 at 6:21
This is a bangladeshi formatFirst create a function
Call the function
answered Apr 18 at 5:24
Often, if a number is big enough to have commas in it, you might want to do without any numbers after a decimal point - but if the value you are showing could ever be small, you would want to show those decimal places. Apply number_format conditionally, and you can use it to both add your commas and clip off any irrelevant post-point decimals.
Works well if you are showing a calculated value derived from a real world input. answered Jun 19, 2013 at 16:37
Give it a try:
answered May 12 at 8:07
How do you print a number with commas as thousands separators in PHP?The number_format() function rounds numbers and adds commas as a thousands separator.. number_format($n) rounds $n to the nearest whole number and adds commas in between thousands. ... . number_format($n,$p) rounds $n to $p decimal places, adding commas between thousands.. How should comma separated values be stored in PHP?The comma separated list can be created by using implode() function. The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function.
What is number format PHP?The number_format() function is an inbuilt function in PHP which is used to format a number with grouped thousands. It returns the formatted number on success otherwise it gives E_WARNING on failure. Syntax: string number_format ( $number, $decimals, $decimalpoint, $sep )
|