“Rounding1” (Solution)
Answer
| Number | Round | Floor | Ceiling | Truncate | Format |
| -2.9 | -3 | -3 | -2 | -2 | -3 |
| -0.5 | 0 | -1 | 0 | 0 | -1 |
| 0.3 | 0 | 0 | 1 | 0 | 0 |
| 1.5 | 2 | 1 | 2 | 1 | 2 |
| 2.5 | 2 | 2 | 3 | 2 | 3 |
| 2.9 | 3 | 2 | 3 | 2 | 3 |
Explanation
If the number is exactly halfway between two possibilities, the following rules will work:
- Math.Round rounds to the nearest even integer (by default).
- Math.Floor rounds down towards the negative infinity.
- Math.Ceiling rounds up towards the positive infinity.
- Math.Truncate rounds down or up towards zero.
- String.Format rounds towards the number away from zero.