# Thread: Pence to pounds sterling

1. ## Pence to pounds sterling

Hi all,

I have a table holding the price of items in pence, for example;

699
2399

but i need to display them to screen in UK pounds thus;

6.99

or

23.99

kind regards,
John

2. By the looks of things, dividing the price in pence by 100 will give you the price in pounds:

PHP Code:
``` \$pence = 699;echo \$pence / 100; // 6.99  ```
I'd recommend using the DECIMAL datatype for storing prices in your database though, as this will allow you to store sums like 6.99 and 23.99 without having to do any formatting or arithmetic when it comes to displaying the prices

3. Originally Posted by SJH
By the looks of things, dividing the price in pence by 100 will give you the price in pounds:

PHP Code:
``` \$pence = 699; echo \$pence / 100; // 6.99  ```
I'd recommend using the DECIMAL datatype for storing prices in your database though, as this will allow you to store sums like 6.99 and 23.99 without having to do any formatting or arithmetic when it comes to displaying the prices
Wonderful help, thankyou so much

4. Wont work with the likes of 710 pence e.g.
PHP Code:
``` \$pence = 710 /100;//echo \$pence / 100; // 7.1echo number_format( \$pence, 2) ; // 7.10  ```
number_format
money_format

5. Originally Posted by Cups
Wont work with the likes of 710 pence e.g.
PHP Code:
``` \$pence = 710 /100;//echo \$pence / 100; // 7.1echo number_format( \$pence, 2) ; // 7.10  ```
number_format
money_format
Or more ideally...

numfmt_format_currency

6. Originally Posted by Ren
Or more ideally...

numfmt_format_currency
...which will be really useful when PHP5.3 is widely adopted!

Until then, though, it looks like number_format is the way to go.

7. Originally Posted by Ren
Or more ideally...

numfmt_format_currency
Cheers, something new for today!

Great, that one's going to be easy to remember ... I'll switch to using an IDE when doing that ... looks like a job for auto-complete

8. Should look at the whole new Internationalization Extension! Jake, while it comes with PHP 5.3, it is available for previous versions. And it is going to be built into PHP 6 along with full Unicode support. Yay!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•