Use the format %f for printing floating numbers : float number « Data Type « C Tutorial






#include <stdio.h>

main()
{
    float f1 = 0.23456;

    printf("%f \n", f1);
}

By default, %f prints output with 6 decimal places

To output with 8 columns and 3 decimal places

#include <stdio.h>

main()
{

    float f1 = 123456789.23456;

    printf("%f \n", f1);
    printf("%8.3f \n", f1);
}
123456792.000000
      123456792.000








2.17.float number
2.17.1.C provides two main floating-point representations: float (single precision) and double (double precision).
2.17.2.Formats for representing floating points
2.17.3.Use the format %f for printing floating numbers
2.17.4.For printing double you can use %lf.