I would like to "cap" a number in Ruby (on Rails).
For instance, I have, as a result of a function, a float but I need an int.
I have very specific instructions, here are some examples:
If I get 1.5
I want 2
but if I get 2.0
I want 2
(and not 3
)
Doing number.round(0) + 1
won't work.
I could write a function to do this but I am sure one already exists.
If, nevertheless, it does not exist, where should I create my cap function?
question from:
https://stackoverflow.com/questions/884512/how-to-cap-and-round-number-in-ruby 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…