Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一个双精度数和所需的舍入数,我如何得到下一个bigger/smaller rounded number?
bigger/smaller rounded number
样本
N = 10.476 Prec = 0.25 Smaller = 10.25 Bigger = 10.50 N = 0.837 Prec = 0.005 Smaller = 0.835 Bigger = 0.840
def round_smaller(n, prec) (n / prec).floor * prec end def round_bigger(n, prec) (n / prec).ceil * prec end