C: printing long double using printf
Posted by Joys of Programming on in C/C++
If you want to use very large floating numbers in C beyond what can be stored using double, use long double.This is useful for large scale scientific computations
Printing a long double is shown here
#include <stdio.h>
int main()
{
/*Floating point number - double*/
long double fvar = 25.01;
/*Printing size of a double*/
printf ("Size of long double %i bytes\n", sizeof(fvar));
/*Printing double*/
printf ("%Lf\n", fvar);
printf ("%Lg\n", fvar);
/*Printing double*/
printf ("%Le\n", fvar);
return 0;
}
The output of this program
Size of long double 12 bytes 25.010000 25.01 2.501000e+01
As you may have noticed, the size of a long double is 12 bytes. There are three ways by which we printed the long double. You have to prepend L before
- f
- g
- e: with an exponential format
to print long double numbers
Comments: