im trying to learn how to make a if/then statement that will take a number, possibly with a decimal and round it to the nearest integer. Like so..

if 3.4 is the number, then the final would be 3 not 3.4

how would i do so?

Featured Replies

- 1
1. Regrettably, for negative numbers williamhemsworth's solution does not work (moreover, gives wrong result - for example, it yields 0 for -0.9 but nearest integer value for -0.9 is -1). Right solution: [code=cplusplus] #include <cmath> ... double round(double x) { bool negative = false; if (x < 0.0) { x … Read More

This topic has been dead for over six months. Start a new discussion instead.

Recommended Topics