なんとなく四捨五入したい気持ち
小数点ほにゃららで四捨五入したい
class Numeric def roundoff(d=0) x = 10**d if self < 0 (self * x - 0.5).ceil.quo(x) else (self * x + 0.5).floor.quo(x) end end end 1000.45.roundoff(1)
小数点ほにゃららで四捨五入したい
class Numeric def roundoff(d=0) x = 10**d if self < 0 (self * x - 0.5).ceil.quo(x) else (self * x + 0.5).floor.quo(x) end end end 1000.45.roundoff(1)