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

1 answer 193 views
2 answers 200 views
1 answer 156 views
1 answer 173 views
1 answer 160 views
...