How can I round up to the next hundred? Using Ruby 2.3.2.
48 -> 100
52 -> 100
112 -> 200
Tried 48.round(-2)
but that rounds down. Trialed some BigDecimal values, but that got me nowhere.
How can I round up to the next hundred? Using Ruby 2.3.2.
48 -> 100
52 -> 100
112 -> 200
Tried 48.round(-2)
but that rounds down. Trialed some BigDecimal values, but that got me nowhere.
Divide by 100 first then multiply back.
(48/100.0).ceil * 100
Use Integer#ceil
/Float#ceil
, saying that you want it to round to two places before the comma:
48.ceil(-2)
This isn't available in Ruby 2.3.0, but it is in Ruby >= 2.4.0.