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 210 views
1 answer 214 views
1 answer 215 views
1 answer 225 views
1 answer 266 views
1 answer 189 views
1 answer 172 views
...