puts “”, “#{ftemp} F is #{ctemp.round} C.”
puts “#{ftemp} F is %d C.” % ctemp
puts “#{ftemp} F is %.2f C.” % ctemp
rounded_ctemp = format( “%.2f”, ctemp )
puts “#{ftemp} F is #{rounded_ctemp} C.”
puts "Fahrenheit to Centigrade Conversion
Input a temperature in Fahrenheit:"
STDOUT.flush
ftemp = gets.to_f
ctemp = (ftemp - 32) / 1.8
rounded_ctemp = format( “%.2f”, ctemp )
puts “”,
“#{ftemp} F is #{ctemp.round} C.”,
“#{ftemp} F is #{ctemp.floor} C.”,
“#{ftemp} F is %.2f C.” % ctemp,
“#{ftemp} F is #{rounded_ctemp} C.”
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.