Rounding[edit | edit source]
To round a number, you need to look at the digits right of the decimal. If the first digit right of the decimal is equal or higher than 5 in rank (see Spelling out numbers), we add 1 to the integer part of the number, lopping off digits right of the decimal; this is known as rounding up. If the first digit right of the decimal place is less than 5 in rank, we simply rewrite the number again excluding all the digits right of the decimal place; this is known as rounding down. Note that after the number is rounded up or down all of the digits right of the decimal are discarded and only the digits left of the decimal are written.
Rounding to integer[edit | edit source]
The most basic form of rounding is to replace an arbitrary number by an integer.
There are many ways of rounding a number y to an integer q. The most common ones are
- round down (or take the floor, or round towards minus infinity): q is the largest integer that does not exceed y.
- round up (or take the ceiling, or round towards plus infinity): q is the smallest integer that is not less than y.
- round towards zero (or truncate, or round away from infinity): q is the integer part of y, without its fraction digits.
- round away from zero (or round towards infinity): if y is an integer, q is y; else q is the integer that is closest to 0 and is such that y is between 0 and q. The signum function is used to determine the sign
- round to nearest: q is the integer that is closest to y.
The first four methods are called directed rounding, as the displacements from the original number y to the rounded value q are all directed towards or away from the same limiting value (0, +∞, or −∞).
If y is positive, round-down is the same as round-towards-zero, and round-up is the same as round-away-from-zero. If y is negative, round-down is the same as round-away-from-zero, and round-up is the same as round-towards-zero. In any case, if y is integer, q is just y. Here the table with the rounding methods:
The choice of rounding method can have a very significant effect on the result.