Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2012, 04:27 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Math Help

Hey all,


I was wondering when you come up with a addition or subtraction of numbers with a decimal how you can get the zero or zeros to show up.

eg.. instead of 139.9

I would like to see 139.90

or instead of 300.

I would like to see 300.00

Hope ya understand..

Thanks in advance.


Slayer.
SlayerACC is offline   Reply With Quote
Old 11-07-2012, 05:05 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Use a print formatter:
PHP Code:
printf("%0.2f"139.9); 
If its for monies, then using money_format would be better if you have it available since its locale aware. No matter the case, having 139.90 instead of 139.9 is the difference between (string)139.90 and (double)139.9.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
SlayerACC (11-07-2012)
Old 11-07-2012, 08:09 PM   PM User | #3
poyzn
Regular Coder

 
poyzn's Avatar
 
Join Date: Nov 2010
Posts: 265
Thanks: 2
Thanked 61 Times in 61 Posts
poyzn is on a distinguished road
or number_format
__________________
Ushousebuilders.com
poyzn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:30 PM.


Advertisement
Log in to turn off these ads.