Rounding to 2 Decimal Places

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
Nick11380
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2011 10:20 am

Rounding to 2 Decimal Places

Post by Nick11380 »

I'm really struggling to see how to do this. The following number is being posted:

As of <span id="theTime"></span> GMT, the gold price per ounce</a> in the UK is £'.$results['ounce_price'];

I want 'ounce_price' to be rounded to decimal places but can't figure how to do this.

Does 'round($results,2) ' mean anything in this situation? Where can I place the code. I'm a little confused, any help would be hugely appreciated!
theyapps
Forum Newbie
Posts: 8
Joined: Tue Sep 06, 2011 12:47 am

Re: Rounding to 2 Decimal Places

Post by theyapps »

After $results['ounce_price'] has been set you can do:

round($results['ounce_price'], 2);
Nick11380
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2011 10:20 am

Re: Rounding to 2 Decimal Places

Post by Nick11380 »

Perfect! Thank you very much, fixed the problem.
theyapps
Forum Newbie
Posts: 8
Joined: Tue Sep 06, 2011 12:47 am

Re: Rounding to 2 Decimal Places

Post by theyapps »

Welcome :)
Post Reply