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 124 views
1 answer 132 views
1 answer 135 views
1 answer 129 views
1 answer 174 views
1 answer 114 views
1 answer 102 views
...