Number format in PHP

Discussion in 'PHP' started by Nite4000, Oct 19, 2007.

  1. #1
    I made a calculator and i use number format to fix the numbers so its understandable.

    The problem is that when it reached more then 8,000 to & by 60% it is using the 8 and not the 8,000 so its giveing the wrong answer its giveing $12.80 instead of $12,800

    is there a way to fix this. I can provide a url to my site if you need to see it.

    i have the number format wrote like this

    <?php echo number_format("$var","2",".",",") ; ?>
     
    Nite4000, Oct 19, 2007 IP
  2. Koster

    Koster Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Convert your number format from 8,000 to 8000 when you do any calculations.
    Number with '.' in PHP indicate fractional number.
    There is no number in PHP with ',' - it is only understandable variant for us.
    That's why, you number must be with out any '.' or ',' separators.
    Easy step to convert is to use str_replace(',','',$var).
     
    Koster, Oct 23, 2007 IP