Advanced Search

Results 1 to 3 of 3

Thread: Add code for decimal places

  1. #1
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Add code for decimal places

    Good day!

    I want to know where I can put this code :
    PHP Code:
     number_format($num), 2
    I have this code:
    PHP Code:
    echo mysql_result ($result,$ctr,"inputqty"); 
    I want the output if this code is in 2 decimal places for example the output in this code is: 1.9856211 I want to become is like this 1.99

    I hope somebody can help me...thank you..
    Last edited by rhodarose; 11-22-2010 at 12:46 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,675
    Thanks
    43
    Thanked 3,125 Times in 3,091 Posts
    Blog Entries
    12

    Default

    What's the output of echo mysql_result ($result,$ctr,"inputqty"); ? If it's a number and a number only and is always less than 1,000 (or if it's 1,000 or more, a comma's OK) then:

    PHP Code:
    echo number_format(mysql_result ($result,$ctr,"inputqty"), 2); 
    But PHP sometimes doesn't like nesting, so to be on the safe side:

    PHP Code:
    $num mysql_result ($result,$ctr,"inputqty");
    echo 
    number_format($num2); 
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    What's the output of echo mysql_result ($result,$ctr,"inputqty"); ? If it's a number and a number only and is always less than 1,000 (or if it's 1,000 or more, a comma's OK) then:

    PHP Code:
    echo number_format(mysql_result ($result,$ctr,"inputqty"), 2); 
    But PHP sometimes doesn't like nesting, so to be on the safe side:

    PHP Code:
    $num mysql_result ($result,$ctr,"inputqty");
    echo 
    number_format($num2); 
    Thank you...

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
  •