Precision Setting in C

Precision Setting :

Here, in this page we will discuss about the Precision Setting in C. For both float and double number outputs, precision is indicated by the number of digits after the decimal point. 

Precision handling

About Precision Setting :

  • Precision, which is represented by the dot (.) symbol, determines the correctness of real numbers.
  • The precision, or accuracy, of the real number must be specified when printing the real numbers.
  • The default precision, which is six decimal digits after the decimal point, will be used if the precision is not specified.
  • Example of Precision of  floating point number : 

        printf(“% .6f”, x) , it will print 6 digits after decimal .

Examples of Precision Setting  :

Let,s see some example for better understanding :

Example 1:

Run
#include<stdio.h>

int main() {
    float val = 2.1;
    printf("Six decimal point : % .6f\n", val);
    printf("Three decimal point : %.3f\n", val);
    printf("Default Precision : %f", val);
    return 0;
}

Output :
Six decimal point :  2.100000
Three decimal point : 2.100
Default Precision : 2.100000

Example 2 :

Run
#include<stdio.h>

int main() {
    double val = 4.12;
    printf("Six decimal point : % .6f\n", val);
    printf("Three decimal point : %.3f\n", val);
    printf("Default Precision : %f", val);
    return 0;
}
Output :
Six decimal point :  4.120000
Three decimal point : 4.120
Default Precision : 4.120000

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription