🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Converting between different temperature scales is a basic operation frequently required in various domains, from scientific computations to everyday applications. In this post, we'll dive into a TypeScript program that converts temperatures from Fahrenheit to Celsius.
2. Program Overview
The conversion from Fahrenheit to Celsius can be achieved using the formula (Fahrenheit - 32) * 5/9. In this blog post, we're going to create a function named fahrenheitToCelsius which accepts a temperature in Fahrenheit as its parameter and returns the converted temperature in Celsius.
3. Code Program
// Function to convert Fahrenheit to Celsius
function fahrenheitToCelsius(fahrenheit: number): number {
return (fahrenheit - 32) * 5/9;
}
// Test the function
const fahrenheitTemperature = 77;
const celsiusTemperature = fahrenheitToCelsius(fahrenheitTemperature);
console.log(`${fahrenheitTemperature}°F is approximately equal to ${celsiusTemperature.toFixed(2)}°C.`);
Output:
77°F is approximately equal to 25.00°C.
4. Step By Step Explanation
1. We begin by defining the function fahrenheitToCelsius. It receives one argument: the temperature in Fahrenheit.
2. Within the function, we apply the conversion formula (Fahrenheit - 32) * 5/9 to compute the temperature in Celsius.
3. To demonstrate the function's utility, we then test it with a Fahrenheit value of 77.
4. The outcome, being the corresponding temperature in Celsius, is then displayed on the console. For precision, we use the toFixed(2) method to round the Celsius value to two decimal places.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment