Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: decimal point

  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post

    decimal point

    Hi everybody
    my script calculate some values from the database and its work fine but i just need to define how many number to show after the decimal point , how can i do it???

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    John

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    it didint solve my problem

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Then you're going to need to show your code. The function I linked to, if used properly, will format the number for display how you want it.
    John

  • #5
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    ok maybe there is a way but I didn't pay attention. anyway
    My code result is like this
    PHP Code:
    //suppose $number1=5 and $number2=3
    $result $number1$number2;
    echo 
    $result//will print 1.666666666 but i want it to print just 1 number after the decimal point 

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Well, no advise is going to solve your problem if you don't "pay attention", or as your code above show, didn't try it.
    John

  • #7
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I didnt find anything that suit my case, the number_format() as i can see its just count from right to left
    Excuse me, im a new coder .
    Last edited by skmd; 01-05-2008 at 02:33 AM.

  • #8
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    PHP Code:
    $number1 5;
    $number2 3;
    $result round($number1/$number2,1);
    print 
    $result
    Is that what you're looking for?

  • Users who have thanked bcarl314 for this post:

    skmd (01-05-2008)

  • #9
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    Yes , thats exactly what I want.
    Thank you

  • #10
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    For future reference that was the round() function it can be used:

    PHP Code:
    <?php
    round
    ($string'decimal_places');
    ?>
    Example:

    PHP Code:
    <?php
     
    $string 
    "7.938";
    $string round($string'2');
     
    ?>
    Output: 7.94


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •