Latox
Latox

Reputation: 4705

PHP rounding, round/ceil/floor??

Say I have the two following numbers:

$a = 77.5;
$b = 74.5;

How would I get the following:

$a = 80;
$b = 70;

I have looked at round, ceil and floor but I can't figure out how to do it.

Thank you.

Upvotes: 4

Views: 3564

Answers (2)

knittl
knittl

Reputation: 265928

PHP supports negative precision for its round function:

$a = round($a, -1);

it's pretty much the same as writing:

$a = round($a/10)*10;

Upvotes: 10

Ben
Ben

Reputation: 57318

You've got to move your decimals over some, then ceil-ify.

ceil($a/10)*10

Upvotes: 2

Related Questions