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

Tags: , ,

Comments:

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.