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 127 views
1 answer 121 views
1 answer 119 views
1 answer 107 views
1 answer 88 views
1 answer 163 views
1 answer 139 views
...