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
Comments: