How to rounds up a float to an integer in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h> 

int main(int argc, char **argv) 
{
    float value, result;
    
    value = 5.2;
    result = ceil(value);
    printf("The floor of %.2f is %.2f\n", value, result); // 6.00
    
    value = 5.4;
    result = ceil(value);
    printf("The floor of %.2f is %.2f\n", value, result); // 6.00
    
    value = 5.5;
    result = ceil(value);
    printf("The floor of %.2f is %.2f\n", value, result); // 6.00

    value = 5.6;
    result = ceil(value);
    printf("The floor of %.2f is %.2f\n", value, result); // 6.00

    return(0);
}


/*
run:

The floor of 5.20 is 6.00
The floor of 5.40 is 6.00
The floor of 5.50 is 6.00
The floor of 5.60 is 6.00


*/


answered May 20, 2015 by avibootz

Related questions

2 answers 224 views
224 views asked May 20, 2015 by avibootz
2 answers 201 views
201 views asked Feb 13, 2017 by avibootz
1 answer 172 views
172 views asked Jan 12, 2017 by avibootz
2 answers 209 views
209 views asked May 1, 2015 by avibootz
1 answer 266 views
...