box-o-sand/kiddofun/rounding.rb
2016-09-29 18:07:11 -04:00

10 lines
360 B
Ruby

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)}"