Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

round float in C

#include <stdio.h>

int main (){
    float a;
    printf("
Enter a real number here please: ");
    scanf("%f",&a);
    
    printf("
Printing Number with different precision: ");
    printf("
  Number default precision: %f", a);
    printf("
  Number in (0 d.p.): %.0f", a);
    printf("
  Number in (1 d.p.): %.1f", a);
    printf("
  Number in (2 d.p.): %.2f", a);
    printf("
  Number in (3 d.p.): %.3f", a);
    printf("
  Number in (3 d.p.): %.4f", a);
    return 0;
}
Source by fresh2refresh.com #
 
PREVIOUS NEXT
Tagged: #float #C
ADD COMMENT
Topic
Name
6+3 =