I-M-JM
I-M-JM

Reputation: 15950

php nearest ten-th value

I am getting a max value through value. It can be any digit (whole number). I want it to take to next tenth-value, using PHP

Example:

If value is 66, then I need value 70
If value is 6, then I need value 10
If value is 98, then I need value 100

Upvotes: 0

Views: 600

Answers (3)

Nebojsa Jevdjovic
Nebojsa Jevdjovic

Reputation: 116

or

echo round(66,-1);

up to 30 characters

Upvotes: 1

Chandresh M
Chandresh M

Reputation: 3828

$num = 66;

    $val = ceil($num / 10) * 10;

echo $val;

Thanks.

Upvotes: 1

Gumbo
Gumbo

Reputation: 655269

This is an arithmetic problem:

y = ceil(x / 10) * 10

If you’re looking just for the nearest decade, use round instead.

Upvotes: 6

Related Questions