Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php - number_format()

Options
  • 18-06-2007 8:27pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    Im formating a number say 6.788 and with the number is being rounded up to 7 by number_format or or 439.978 rounded to 440, is there a way i can tell the it to only take characters from the left side of the decimal point with out rounding up or down?


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    you could do this
    $number = "34.234234234234";
    $integer = explode(".", $number);
    
    echo $integer[0]; 
    


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Ph3n0m wrote:
    you could do this
    $number = "34.234234234234";
    $integer = explode(".", $number);
    
    echo $integer[0]; 
    

    Fair play to you.:D I know theres a way to do all these little things but its hard to know what to search for on the php.net site!


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    You could use floor();

    I had also tried sprintf: [PHP]$fNum = 6.788;
    echo sprintf( '%d - %.0f', $fNum, $fNum ); // Printed "6 - 7"[/PHP]


Advertisement