SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    what is the easiest way to go about this?

    kind regards,
    John

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #3
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SJH View Post
    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. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Wont work with the likes of 710 pence e.g.
    PHP Code:
    $pence 710 /100;
    //echo $pence / 100; // 7.1

    echo number_format$pence2) ; // 7.10 
    number_format
    money_format

  5. #5
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Wont work with the likes of 710 pence e.g.
    PHP Code:
    $pence 710 /100;
    //echo $pence / 100; // 7.1

    echo number_format$pence2) ; // 7.10 
    number_format
    money_format
    Or more ideally...

    numfmt_format_currency

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren View Post
    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.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Ren View Post
    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. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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!
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

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