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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php - number_format()

  • 18-06-2007 7:27pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,571 ✭✭✭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