Formatting Numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stantheman
Forum Commoner
Posts: 38
Joined: Wed May 26, 2004 8:57 am

Formatting Numbers

Post by stantheman »

I want to be able to fomrat my numbers to something like this
100,000.00

How would i go about this with this function or do i have the wrong function

sprintf("%01.2f", $money);
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

give it a try, think about how much time you could have saved instead of posting if you just droped it into a php file and gave it a go
stantheman
Forum Commoner
Posts: 38
Joined: Wed May 26, 2004 8:57 am

Post by stantheman »

i put it into the code but the format i get it 100000.00 but i want 100,000.00
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

oh ok, well you could make a simple function to count every 3 numbers and insert a ","

but i think to do this you will have to treat the float as a string
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

dull1554 wrote:oh ok, well you could make a simple function to count every 3 numbers and insert a ","
really? :P

[php_man]number_format[/php_man]
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

*opens mouth and inserts foot*
after posting i dusted off the old php manual and found it, i just thought to hit f5 before i made an even bigger fool of myself

sorry for the slight oversight......
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

dull1554 wrote:*opens mouth and inserts foot*
after posting i dusted off the old php manual and found it, i just thought to hit f5 before i made an even bigger fool of myself

sorry for the slight oversight......
lol dont worry, i never knew about that function either. My memory was refreshed when I seen it

:wink:
Post Reply