 |

Perchpole
User
May 22, 2008, 4:46 PM
Post #1 of 3
(200 views)
Shortcut
|
|
Who Stole My Zeros?!
|
Can't Post
|
|
Here's a quickie for the mathematicians out there... I'm using a record to perform a calculation that generates a simple product shipping cost. The calculation is the product weight multiplied by a fixed number. Something like this: <?php echo $record['weight'] * 5 ?> Although this works fine in practice (and can be used in systems like Paypal, etc.) the figures don't look right. For example, instead of £2.50 what you see is £2.5! Instead of £7.00 all you get is £7. Simple question: How do I rework the code to display the missing zeros?! :0o Perch
|
|
|  |
 |

Dave
Staff
/ Moderator

May 22, 2008, 5:37 PM
Post #2 of 3
(197 views)
Shortcut
|
|
Re: [Perchpole] Who Stole My Zeros?!
[In reply to]
|
Can't Post
|
|
Hi Perch, We're going to have to use a PHP function for this. instead of this: <?php echo $record['weight'] * 5 ?> try this: <?php echo number_format($record['weight'] * 5, 2) ?> The ", 2" tells it to _always_ show 2 decimals, even then they're 00. This will also add thousands separators. So one million will display like this: 1,000,000.00. If it's a problem we can have it not add those. Let me know what works best for you. Hope that helps! Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

Perchpole
User
May 22, 2008, 5:47 PM
Post #3 of 3
(196 views)
Shortcut
|
|
Re: [Dave] Who Stole My Zeros?!
[In reply to]
|
Can't Post
|
|
Dave - Seriously, you must stop eating that brainy food and give us mere mortals an opportunity to shine sometimes!
Thanks, Perchpole
|
|
|  |
|