C float literal

Float constant

You could omit digits before the decimal point and specify a number as .5 instead of 0.5. A floating-point zero should be written as 0.0. The floating-point number may include an exponent specification of the form:e + exp. For example, 1.2e34 is a shorthand version of 1.2*1034.

float literal

The default type of a floating-point constant is double. You can append the suffix F or f to assign a constant the type float.

float f_var = 123.456F; // Initialize a float variable.

Example - Scientific notation

Define float in In scientific notation (The E notation).


#include <stdio.h>
 /*from w ww .  j  av a  2  s .co m*/
int main(){
    float lightyear=5.878E12;
    float jupiter=483400000;
    float distance;
 
    distance=jupiter/lightyear;
 
    printf("Jupiter is %f light years from the sun.\n",distance);
 
    return(0);
}

The code above generates the following result.





















Home »
  C Language »
    Language Basics »




C Language Basics
Data Types
Operator
Statement
Array