C: Printing float using printf

Posted by Joys of Programming on in C/C++

float in C is used to represent floating point numbers. It’s declaration is as simple as


float varname;

The following program shows how to print a float.


#include <stdio.h>

int main()
{
 /*Floating point number*/
 float fvar = 25.0;

 /*Printing floating point number*/
 printf ("%f\n", fvar);

 return 0;
}

Let’s check the output


25.000000

The output is upto a precision of 6 digits after the decimal point. This is a behavior by default which can be changed

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.