Java Reference
In-Depth Information
Rounding Modes
Not all real numbers can be exactly represented in binary floating-point format in finite number of bits. Therefore,
real numbers that cannot be exactly represented in a binary floating-point format must be rounded. There are four
rounding modes:
Round toward zero
Round toward positive infinity
Round toward negative infinity
Round toward nearest
Rounding Toward Zero
This rounding mode is also called truncation or chop mode. In this rounding mode, the total number of bits (or
digits) that is retained from the original number is the same as the number of bits available to store the floating-
point number in the given format. The rest of bits are ignored. This rounding mode is called “rounding toward zero”
because it has the effect of making the rounded result closer to zero. Some examples of rounding towards zero are
shown in Table 3-14 .
Table 3-14. Examples of Rounding Towards Zero
Original Number
Available Number of Binary Points
Rounded Number
1.1101
2
1.11
-0.1011
2
-0.10
0.1010
2
0.10
0.0011
2
0.00
Rounding Toward Positive Infinity
In this rounding mode, numbers are rounded to a value closer to the positive infinity. Some examples of rounding
towards positive infinity are shown in Table 3-15 .
Table 3-15. Examples of Rounding Towards Positive Infinity
Original Number
Available Number of Binary Points
Rounded Number
1.1101
2
10.00
-0.1011
2
-0.10
0.1010
2
0.11
0.0011
2
0.01
 
Search WWH ::




Custom Search