Php add commas to numbers thousands
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.3k48 gold badges171 silver badges217 bronze badges asked Jan 3, 2011 at 6:49
Ahmad FouadAhmad Fouad 3,81714 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,2744 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 write 1000000 with commas?A comma is placed every third digit to the left of the decimal point and so is used in numbers with four or more digits. Continue to place a comma after every third digit. For example: $1,000,000 (one million dollars)
How can I set 2 decimal places in PHP?Use number_format() Function to Show a Number to Two Decimal Places in PHP.. Use round() Function to Show a Number to Two Decimal Places in PHP.. Use sprintf() Function to Show a Number to Two Decimal Places in PHP.. Related Article - PHP Number.. How do you put a comma in a foreach loop?If your intention is to show comma after each element except the last one, you can easily use $loop->last() inside your foreach.
|