y u no do it?

Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

Starts at just \$1 per CPM or \$0.10 per CPC.

# Another Question

Discussion in 'PHP' started by kc3, May 10, 2005.

1. #1
I have another stupid question, lol, if you have a number that's one decimal place how do you add a 0 after it. For example how do you determine if variable \$number (say \$number = 19.5 ) has one decimal place and make it add a 0 after it to make \$number = 19.50. (lol, there is an actual reason for this) Though I also have the same question for the reverse, say \$number = 19.539 how would I be able to make \$number = 19.54?

, May 10, 2005 IP
2. ### sarahkiTamerStaff

Messages:
26,231
3,857
108
Trophy Points:
665
#2
May 11, 2005 IP
3. ### kc3Peon

Messages:
857
15
0
Trophy Points:
0
#3
Thanks, I'll check it out.

, May 13, 2005 IP
4. ### neterslandreauPeon

Messages:
279
8
0
Trophy Points:
0
#4
May 14, 2005 IP
5. ### kc3Peon

Messages:
857
15
0
Trophy Points:
0
#5
All of those worked great, but for some reason I still have a problem when a price is \$10.50 it shows it as \$10.5, if it's \$7.00 it shows it as \$7. I need the extra zeros, how do I do this is there is only one or less digits after the decimal?

, May 26, 2005 IP
6. ### draculusPeon

Messages:
63
3
0
Trophy Points:
0
#6
You should use the money_format() function. It's purpose is to do what you want to do. You might also look at number_format().

May 27, 2005 IP
7. ### J.D.Peon

Messages:
1,198
64
0
Trophy Points:
0
#7
Use sprintf:

<?= sprintf("%.02f", \$number) ?>

J.D.

, May 27, 2005 IP
8. ### sarahkiTamerStaff

Messages:
26,231
3,857
108
Trophy Points:
665
#8
May 27, 2005 IP
9. ### noppidgunnin' for the quota

Messages:
4,246
232
0
Trophy Points:
135
#9

Number format returns a string.

Sprintf type casts it as a float that you can still do math with.

May 27, 2005 IP
10. ### J.D.Peon

Messages:
1,198
64
0
Trophy Points:
0
#10
Just as kc3 says, number_format won't format 10.5 as 10.50.

J.D.

, May 27, 2005 IP

Messages:
857