Jump to content

Number Formatting


jayR

Recommended Posts

I'm currently running a page that reads in a file created by our mainframe with various stats for the week.  Some of these are averages that have up to 4 decimal places, while others have no decimal places at all.  I am looking at the number_format() function, but it looks like you have to tell it how many decimal places to place in the number, and I need to format the mainframe's numbers because it doesn't add commas to the thousand's place (i.e. 1,000 = 1000).  Is there a function that will simply check the number of decimal places then display them all?  Or would I have to write something custom for this problem?  Thanks.
Link to comment
https://forums.phpfreaks.com/topic/13729-number-formatting/
Share on other sites

You might want to look into [url=http://www.php.net/manual/en/function.round.php]round()[/url].
You can tell it how many numbers to leave after the dot. And you alos might want to check [url=http://www.php.net/manual/en/function.number-format.php]number_format()[/url] to drop commas and to format your string ([url=http://www.php.net/manual/en/function.round.php]round()[/url] doesnt like commas- just numbers and a dot).

Orio.
Link to comment
https://forums.phpfreaks.com/topic/13729-number-formatting/#findComment-53292
Share on other sites

I'm using number_format right now, and thats my whole problem.  I have a variable number of decimal places and number_format requires you to enter the number of decimal places for the number and I was just wondering if there was a function that doesn't require that but still will put the commas in.
Link to comment
https://forums.phpfreaks.com/topic/13729-number-formatting/#findComment-53307
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.