Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    40

    Unanswered: how can i reduce my float ???

    When i have a number 0.4526589642 how can i reduce its float numbers to 0.45 for example to show only the 2 float digits? I want to do this from php source code and not mysql (for example float(3,2) from mysql).

    Thanx

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at floor, round functions

  3. #3
    Join Date
    Feb 2004
    Posts
    533
    Use printf() or sprintf() fucntions

    Use a conversion specification: %.2 designates the number of decimals, 'f' is the Specifier for a Float Point number.
    PHP Code:
    <?php 
    print "<pre>";
    // use printf() or sprintf() for formatted output
    // printf() prints directly to the browser
    printf("%.2f"0.4526589642 );
    print 
    "\n";
    // to assign a variable use sfprint()
    $foo sprintf("%.2f"0.4526589642 );
    print 
    $foo "\n";
    // use additional formatting and text in specification
    printf("Item Price %.2f\n"0.4526589642 );
    print 
    "</pre>";
     
    ?>
    Last edited by savbill; 01-07-06 at 11:56.
    ~

    Bill

  4. #4
    Join Date
    Nov 2005
    Posts
    40
    The sprintf worked fine ! Thanx !

Posting Permissions

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