Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

php - number_format()

  • 18-06-2007 08:27PM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    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,991 ✭✭✭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,655 ✭✭✭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