Here is the solution. It implements the following rules:
- 0 and degrees 10 do not change;
- nine??? rounded to 10,000 (no matter how long);
- a??? rounded to B000 (no matter how long), where B is the number following A.
.
def roundup(n)
n = n.to_i
s = n.to_s
s =~ /\A1?0*\z/ ? n : s =~ /\A\d0*\z/ ? ("1" + "0" * s.size).to_i :
(s[0, 1].to_i + 1).to_s + "0" * (s.size - 1)).to_i
end
fail if roundup(0) != 0
fail if roundup(1) != 1
fail if roundup(8) != 10
fail if roundup(34) != 40
fail if roundup(99) != 100
fail if roundup(100) != 100
fail if roundup(120) != 200
fail if roundup(360) != 400
fail if roundup(990) != 1000
fail if roundup(1040) != 2000
fail if roundup(1620) != 2000
fail if roundup(5070) != 6000
fail if roundup(6000) != 10000
fail if roundup(9000) != 10000
source
share