1. Conclusion </ b>
2. How to use </ b>
3. What I learned from here </ b>
Use the floor method </ b>!
def cal_points(point)
if point < 6000
cal_point = points * 0.05
else
cal_point = points * 0.1
end
puts "The point is#{cal_point.floor}Is a point"
end
In the above, the calculation with a decimal point in the if conditional expression is truncated from # {cal_point.floor}. The floor method is applied to the expression expansion.
Reference URL:
Truncate / round up / round off numbers in Ruby
There are also round method (rounding) and ceil method (rounding up). You can also use ***. Round (1) to "round to the first decimal place" or ***. Round (-1) to round to the first decimal place.
ex)1.23.round(1) #1.2
ex)123.round(-1) #120
Recommended Posts