SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Number Format

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Nottingham England
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Number Format

    Hi,

    I am in the midst of trying to enable a site visitor to purchase a certain number of items, have this number calculated by a price value and then have a total displayed, have tax and shipping added and then have a grand total displayed.

    I have created FLOAT variables to hold all of the calculations which all work ok and I am echo'ing those but want to constrain the resultant displays to 2 decimal places because it is of course currency values.

    I have been attempting to learn PHP from various sources, am totally confused because some use globals in their teaching whilst others insist they mustn't be used and the only references I have found to number formatted displays were when globals WERE being used.

    My declarations and displays are all on the following basis ( I am trying to be a good little pupil and not use globals).. How can I limit these to 2 decimal places?, any help would be greatly appreciated.

    Code:
    //Declaration
     
    $HTTP_GET_VARS['GrandTotal'] = (Double) $HTTP_GET_VARS['Total'] + $HTTP_GET_VARS['VAT'] + $HTTP_GET_VARS['Shipping'];
     
    //Display
     
    Order Total: &pound; <?PHP echo $HTTP_GET_VARS['GrandTotal']; ?>
    Thanks ( knew I should have taken up plumbing).
    It was working when I left last night!

  2. #2
    SitePoint Addict delpino's Avatar
    Join Date
    Nov 2001
    Location
    London
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.antosch-and-lin.com - Language Learning

  3. #3
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    number_format() should do the job for you. take a look here
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Nottingham England
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    That'll teach me to persevere !!...... I guess it helps if ya get the syntax right eh

    I've just deployed it perfectly well.

    Sorry to be such a dumb ***....thanks again for the help.
    It was working when I left last night!


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
  •