How to round a floating-point number to an integer in Ruby

1 Answer

0 votes
x = 9382.4;
y = (x + 1/2r).floor
puts y

x = 9382.5;
y = (x + 1/2r).floor
print y

  
#
# run:
# 
# 9382
# 9383
#

 



answered May 14, 2025 by avibootz

Related questions

...