Control the precision when outputing float type value - C Data Type

C examples for Data Type:Introduction

Introduction

To control precision with floating-point numbers, using numbering schemes between the % sign and the f character conversion specifier.

Demo Code

#include <stdio.h>

int main()//www .  ja  va  2s .  c  o  m
{
    printf("%f", 55.55); 
    
    printf("%.1f", 3.123456); 
    
    printf("\n%.2f", 3.123456); 
    
    printf("\n%.3f", 3.123456); 
    
    printf("\n%.4f", 3.123456); 
    
    printf("\n%.5f", 3.123456); 
    
    printf("\n%.6f", 3.123456); 
    return 0;
}

Result


Related Tutorials