Search
 
SCRIPT & CODE EXAMPLE
 

C

round decimal point in C

#include <math.h>

float val = 37.777779;

float rounded_down = floorf(val * 100) / 100;   /* Result: 37.77 */
float nearest = roundf(val * 100) / 100;  /* Result: 37.78 */
float rounded_up = ceilf(val * 100) / 100;      /* Result: 37.78 */
Comment

C float rounding up

#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;
}
Comment

PREVIOUS NEXT
Code Example
C :: HOW TO ADD FORM IN BOOTSTRAp 
C :: Passing a matrix in a function C 
C :: c code to grade marks 
C :: prime factorization in c 
C :: c language string 
C :: passing two dimensional array to function in c 
C :: syntax 
C :: program to find the average of n numbers using arrays. 
C :: add to beginning of array c 
C :: convert string to int error checking c 
C :: print float number completely in C language 
C :: malloc c 
C :: debian unhold packages 
C :: C program to input the month number and output the month name using switch statement 
C :: argparse allow line break 
C :: Command to create a static library in C 
C :: sqrt function in c 
C :: function that changes all lowercase letters of a string to uppercase. 
C :: how to make two arrays equal in c 
C :: objects in oops 
C :: use frama c online 
C :: string to number in c 
C :: c get int inpot 
C :: convert c code to python online free 
C :: How to declare a string? 
C :: execute asm in c 
C :: #pragma pack(1) in c 
C :: turn on and turn off different device at the same time in rainmaker 
C :: counting 7s in an integer c 
C :: c michael 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =