pavelkor
pavelkor

Reputation: 79

Round number after .20

I'm trying to round up the number after 0.2 so for example if the number is 10.19 it should display 10 if 10.20 or above 11

I did read about the round function but I can't figure how to achieve the effect described above.

Upvotes: 0

Views: 113

Answers (2)

Engineer
Engineer

Reputation: 48813

You may try this:

$rounded = ceil( $yournumber - 0.2 );

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1502786

Just add 0.3:

rounded = round(original + 0.3)

That way, an original value of 10.2 will end up as 10.5, which will be rounded to 11.

Alternatively, you could add 0.8 and then use floor.

(This is all assuming positive values. If your numbers can be negative, you'll need to do a bit more work.)

Upvotes: 1

Related Questions