Search⌘ K
AI Features

Solution: Convert Fahrenheit to Celsius

Understand how to write a Ruby program that converts Fahrenheit to Celsius correctly by using floating-point numbers. Learn the importance of applying the proper conversion formula and data type conversion to preserve decimal precision in user inputs.

We'll cover the following...

Solution

Ruby 3.1.2
fahrenheit = input.to_f
celsius = (fahrenheit - 32) * 5 / 9.0
output = celsius.round(2)

Explanation

  • Line 2: The conversion formula is applied with a ...