Given a temperature value, its unit ("C", "F", or "K"), and a target unit, convert the temperature and round the result to 2 decimal places.
Conversion formulas:
F = C * 9/5 + 32K = C + 273.15C = (F - 32) * 5/9K = (F - 32) * 5/9 + 273.15C = K - 273.15F = (K - 273.15) * 9/5 + 32If the source and target units are the same, return the input value rounded to 2 decimal places.
value = 100, fromUnit = "C", toUnit = "F"212.0value = 32, fromUnit = "F", toUnit = "C"0.0value = 0, fromUnit = "C", toUnit = "K"273.15-1000 <= value <= 1000fromUnit and toUnit are one of "C", "F", or "K"Result should be rounded to 2 decimal placesRun your code to see results
Use Cmd+Enter to run