Celsius to Fahrenheit Formula in Excel and Code

Copy-ready Celsius to Fahrenheit (and Fahrenheit to Celsius) formulas for Excel, Google Sheets, Python, JavaScript, Java, C and C++. Each snippet uses the same exact maths as our converters, so results match to the decimal.

The formula in one line

F = C × 9/5 + 32  ·  C = (F − 32) × 5/9

In code, the main thing to watch is integer division. In languages like Java, C and C++, writing 9/5 with two whole numbers gives 1, not 1.8, and every result will be wrong. Use floating-point literals (9.0/5.0) or multiply before dividing (c * 9 / 5 with c already a double). Python 3 and JavaScript always do true division, so 9/5 is safe there.

Round only when you display a value, not in the middle of a calculation. Rounding early can push a result off by 0.01 or more after a few steps.

Code snippets

Excel

Celsius in cell A1:

=A1*9/5+32
=CONVERT(A1,"C","F")

' Fahrenheit in A1 back to Celsius:
=(A1-32)*5/9
=CONVERT(A1,"F","C")

' Rounded to 2 decimals:
=ROUND(A1*9/5+32,2)

Google Sheets

Same formulas work in Google Sheets; CONVERT supports C, F and K:

=A1*9/5+32
=CONVERT(A1,"C","F")
=(A1-32)*5/9
=CONVERT(A1,"C","K")

// Whole column at once (A2:A):
=ARRAYFORMULA(IF(A2:A="",,A2:A*9/5+32))

Python

def c_to_f(c: float) -> float:
    return c * 9 / 5 + 32

def f_to_c(f: float) -> float:
    return (f - 32) * 5 / 9

print(round(c_to_f(37), 2))   # 98.6
print(round(f_to_c(350), 2))  # 176.67

JavaScript

const cToF = (c) => c * 9 / 5 + 32;
const fToC = (f) => (f - 32) * 5 / 9;

console.log(cToF(100));               // 212
console.log(fToC(350).toFixed(2));    // "176.67"

Java

public class TempConvert {
    static double cToF(double c) { return c * 9.0 / 5.0 + 32.0; }
    static double fToC(double f) { return (f - 32.0) * 5.0 / 9.0; }

    public static void main(String[] args) {
        System.out.printf("%.2f%n", cToF(25));   // 77.00
        System.out.printf("%.2f%n", fToC(98.6)); // 37.00
    }
}

C

#include <stdio.h>

double c_to_f(double c) { return c * 9.0 / 5.0 + 32.0; }
double f_to_c(double f) { return (f - 32.0) * 5.0 / 9.0; }

int main(void) {
    printf("%.2f\n", c_to_f(-40.0)); /* -40.00 */
    printf("%.2f\n", f_to_c(212.0)); /* 100.00 */
    return 0;
}

C++

#include <iostream>
#include <iomanip>

double cToF(double c) { return c * 9.0 / 5.0 + 32.0; }
double fToC(double f) { return (f - 32.0) * 5.0 / 9.0; }

int main() {
    std::cout << std::fixed << std::setprecision(2);
    std::cout << cToF(180) << "\n";  // 356.00
    std::cout << fToC(0) << "\n";    // -17.78
}

Tips for spreadsheets

Excel's CONVERT function understands "C", "F", "K" and "Rank" (Rankine), so =CONVERT(A1,"K","F") converts Kelvin to Fahrenheit directly. Unit codes are case-sensitive: "c" will return an error. If you prefer to see the maths, the plain formula version is easier to audit and works identically in LibreOffice and Google Sheets.

To build a conversion table, put a starting value in A2, enter =A2+1 in A3 and fill down, then put =A2*9/5+32 in B2 and fill down. Format column B with two decimal places. If you just need a ready-made table, the printable Celsius to Fahrenheit chart already has one.

Formula in Roman Urdu / Hindi

Celsius ko Fahrenheit mein badalne ka formula: F = C × 9/5 + 32.

Fahrenheit se Celsius nikalne ka formula: C = (F − 32) × 5/9.

Misal: 37 °C = 98.6 °F.

Test values for your code

Use unrounded values for calculation tests, then test the formatted display separately. These pairs cover the freezing and boiling points, the crossover at −40, and repeating decimals:

For these small test values, compare the unrounded calculation with a tolerance such as 1e-9. Do not compare it with a rounded display value: the correct result for 350 °F differs from 176.67 by about 0.00333. Choose a tolerance appropriate to the values and precision your application needs.

const fToC = (f) => (f - 32) * 5 / 9;

// Unrounded calculations:
console.assert(Math.abs(fToC(350) - 530 / 3) < 1e-9);
console.assert(Math.abs(fToC(0) - (-160 / 9)) < 1e-9);

// Display formatting is a separate test:
console.assert(fToC(350).toFixed(2) === "176.67");
console.assert(fToC(0).toFixed(2) === "-17.78");

Floating-point values such as 98.6 cannot be represented exactly in binary. Use a tolerance for calculation tests and compare formatted strings for display tests. To check any other value, use the Celsius to Fahrenheit converter or Kelvin converter.

Frequently asked questions

What is the Excel formula for Celsius to Fahrenheit?

Use =A1*9/5+32, or the built-in =CONVERT(A1,"C","F"). For the reverse, use =(A1-32)*5/9 or =CONVERT(A1,"F","C").

Why does my Java or C program always give the wrong answer?

Probably integer division: 9/5 evaluates to 1 with whole numbers. Write 9.0/5.0 so the calculation uses floating point.

How do I round the result to 2 decimals in Python?

Use round(value, 2), or format it with f"{value:.2f}" when printing.

Does Google Sheets have a CONVERT function?

Yes. =CONVERT(A1,"C","F") works in Google Sheets as well as Excel.

What is the Fahrenheit to Celsius formula in JavaScript?

const fToC = f => (f - 32) * 5 / 9; then call fToC(98.6) to get 37.