Floating Constants

In this tutorial, we will learn how to create floating point numbers (both single precision and double precision) in the C programming language.


Double Constants

By default, any floating constant is a double constant in C. This means that the compiler allocates memory for the floating constant as if it were a double variable.

There are different ways to represent the number 88.0 as a floating point constant in C. Here are some examples:

88.0  
88.  
88.0e0 
8.8e1  
8.8E1  
8.8e+1  
.88e2  
880.e-1

A floating point constant must include a decimal point and/or an exponent (e or E). The exponent indicates multiplying the number by 10 raised to a certain power. For example, 8.8e1 is the same as 8.8 multiplied by 10 to the power of 1. Additionally, the exponent can have an optional plus or minus sign (+ or -) after the letter E or e.


Float or Long Double Constants

Although a floating point constant is considered a double constant by default, we can instruct the compiler to store it as a float or long double constant. To do this, we add a suffix: F (or f) for float and L (or l) for long double.

For instance, if we want to store the number 88.0 as a float, we can add F (or f) at the end: 88.0f. On the other hand, if we want to store it as a double, we can use 88.0L.


Summary

In this tutorial, we learned how to create a floating constant in C. By default, floating constants are considered “double” numbers. We saw different ways to represent floating constants, such as 88.0 or 8.8e1. We also learned that floating constants must have a decimal point and/or an exponent. If we want to specify that a number should be treated as a “float” or “long double,” we can add a suffix: F for float and L for long double. For example, we can write 88.0f to represent a float or 88.0L to represent a long double.



Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *

Thank you for choosing to leave a comment. Please be aware that all comments are moderated in accordance with our policy. For more information, please review our comments policy. Rest assured that your email address will not be shared with anyone. Kindly refrain from using keywords in your comment. Let’s maintain a respectful atmosphere and engage in meaningful conversations.