box-o-sand/kiddofun/rounding.rb

10 lines
360 B
Ruby
Raw Normal View History

number = Integer(ARGV.fetch(0))
divisor = Float(ARGV.fetch(1, 10.0))
raise 'Invalid divisor' unless divisor % 10 == 0
puts "#{number} - number"
puts "#{(Float(number) / divisor).round(0)} - number divided by #{divisor}"
puts "#{(Float(number) / divisor).round(0) * Integer(divisor)} - " \
"number divided by #{divisor}, multiplied by #{Integer(divisor)}"