Recipe1.11.Converting Celsius to Fahrenheit


Recipe 1.11. Converting Celsius to Fahrenheit

Problem

You have a temperature reading measured in Celsius and need to convert it to Fahrenheit.

Solution

 public static double CtoF(double celsius) {    return (((0.9/0.5) * celsius) + 32); } 

To generate a double result while maintaining the same ratio (9 to 5) as the integers give, 0.9 and 0.5 are used in the calculation.

Discussion

This recipe makes use of the following Celsius-to-Fahrenheit temperature conversion equation:

 TempFahrenheit = ((9 / 5) * TempCelsius) + 32 

The Fahrenheit temperature scale is widely used in the United States. However, much of the rest of the world uses the Celsius temperature scale.



C# Cookbook
Secure Programming Cookbook for C and C++: Recipes for Cryptography, Authentication, Input Validation & More
ISBN: 0596003943
EAN: 2147483647
Year: 2004
Pages: 424

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net