Search code examples
phpnumber-formatting

PHP format a number to have no decimal places?


I have a number (as string) like this: 1.00000

How can I reformat such numbers to only look like 1?

Thanks


Solution

  • Use number_format()

    echo number_format('1.000000'); // prints 1
    

    Or use intval()

    echo intval('1.000000'); // prints 1
    

    Or cast it as an integer

    echo (int) '1.000000'; // prints 1