int .
1.1 → 1, 1.99999999999 → 1, 2.0 → 2
-1.1 → -1, -1.999999999 → -1, -2 → -2
, ? , . , ?
. , , 0.2 * 10 , 2. , , 2. (int) (0.2 * 10) 1 2, " 2" 1.
round (x) is rounded to the nearest integer. Again, if you calculate the round (1.4 + 0.1), the sum of 1.4 and 0.1 is some number very close to 1.5, maybe a little less, maybe a little more, so you don’t know whether it will be rounded to 1.0 or 2.0,
Do you want all numbers from 1.5 to 2.5 to be rounded to 2? Use (int) round (x). You can get a slightly different result if x is 1.5 or 2.5. Perhaps you want to round numbers to 1.9999, but 1.99999999 is rounded to 2. Use double, not float and calculate (int) (x + 0.000001).
source
share