formating money

Discussion in 'PHP' started by x0x, Jun 6, 2010.

  1. #1
    What's the best way to format input such as "10.00" or "10,00" . I need to deduct the user's input from a amount in the database, however with the dots and commas it doesn't let them proceed and gives them an error. I think it's not so professional, so I would like to change how it works. Only whole amounts are allowed, no cents. I need to extract the number somehow and get rid of the unneeded, because they tend to use amounts that I named before instead of just whole numbers.
     
    x0x, Jun 6, 2010 IP
  2. chadayers

    chadayers Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    number_format be what you are looking for. Some additional details are available here: http://php.net/manual/en/function.number-format.php

    $number = 1234.56;
    $english_format_number = number_format($number);
    // 1,235


    - Chad
    www.ChadAyers.org
     
    chadayers, Jun 6, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    danx10, Jun 6, 2010 IP
  4. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    number_format($variable)

    for more decimals use a:

    number_format($variable,4);

    - scripteen.com
     
    qrpike, Jun 6, 2010 IP
  5. aeroz1

    aeroz1 Active Member

    Messages:
    492
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    > I have a textbox that displays money, I cannot find out how to format
    > it so it displayes like '$123.00' what i get now is '123.00'. Can
    > someone point me in the right direction?[/color]

    myvalue.ToString("C");
     
    aeroz1, Jun 7, 2010 IP