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

1 Answer

0 votes
#include <iostream>
#include <cmath>

int main() {
    std::cout << (int)floor(17.893) << "\n";
    std::cout << (int)floor(-14.995) << "\n";
    
    std::cout << (int)17.893 << "\n";
    std::cout << (int)-14.995;
}




/*
run:

17
-15
17
-14

*/

 



answered Jun 8, 2022 by avibootz

Related questions

1 answer 120 views
1 answer 122 views
1 answer 123 views
1 answer 119 views
1 answer 164 views
1 answer 107 views
1 answer 89 views
...