how i can set only 2 decimal digits to my prices?

Discussion in 'PHP' started by Kyriakos, Apr 16, 2008.

  1. #1
    hi

    i want the online store prices to have only 2 decimal digits. the prices in mysql database already have 2 decimal digits but when i calculate the VAT
    <?php echo $row['price']*1.19;?>
    PHP:
    the decimal digits are more than 2 in many cases. how i can set only 2 decimal digits?

    thanks in advance.
     
    Kyriakos, Apr 16, 2008 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    http://ca.php.net/number-format

    
    
    <?php
    
    $number = 1234.5678;
    
    // english notation without thousands seperator
    $english_format_number = number_format($number, 2, '.', '');
    // 1234.57
    
    ?> 
    
    
    
    
    
    
    PHP:
     
    commandos, Apr 16, 2008 IP
  3. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    
    <?php
        echo sprintf( '$%01.2f', $row['price'] * 1.19 );
    ?>
    
    Code (php):
     
    Synchronium, Apr 16, 2008 IP
  4. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Use round($number, 2);
     
    m0nkeymafia, Apr 16, 2008 IP
  5. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #5
    1.20 would become 1.2. Not useful for currency outputs :)
     
    jayshah, Apr 16, 2008 IP
  6. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    thank you man. it's working now. thanks again.
     
    Kyriakos, Apr 16, 2008 IP