How to round down a double to the nearest smaller int in C

1 Answer

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

int main(void) {
    printf("%d\n", (int)floor(17.893));
    printf("%d\n", (int)floor(-14.995));
    
    printf("%d\n", (int)17.893);
    printf("%d\n", (int)-14.995);

    return 0;
}



/*
run:

17
-15
17
-14

*/

 



answered Jun 8, 2022 by avibootz

Related questions

1 answer 136 views
1 answer 132 views
1 answer 129 views
1 answer 114 views
1 answer 102 views
1 answer 174 views
1 answer 151 views
...