I\'m having problems rounding. I have a float, which I want to round to the hundredth of a decimal. However, I can only use .round
which basically turns it in
You can also provide a negative number as an argument to the round
method to round to the nearest multiple of 10, 100 and so on.
# Round to the nearest multiple of 10.
12.3453.round(-1) # Output: 10
# Round to the nearest multiple of 100.
124.3453.round(-2) # Output: 100
you can use this for rounding to a precison..
//to_f is for float
salary= 2921.9121
puts salary.to_f.round(2) // to 2 decimal place
puts salary.to_f.round() // to 3 decimal place
what about (2.3465*100).round()/100.0
?