EOB
EOB

Reputation: 3085

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

Upvotes: 9

Views: 42140

Answers (2)

Jords
Jords

Reputation: 1

You can use the floor method for it to stay as a float

floor(1.000000)

Upvotes: 0

John Conde
John Conde

Reputation: 219894

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

Upvotes: 35

Related Questions