Table Of Contents

Rounding in the Fixed-Point Data Type

Last Modified: August 9, 2019

Rounding in the fixed-point data type occurs when the precision of the input value or the result of an operation is greater than the precision of the output type of an operator.

When rounding occurs, the value is coerced to a value with the same precision as the output type according to the rounding mode you select for the operator.

Many decimal (base 10) numbers are not exactly representable as binary (base 2) numbers. Likewise, the results of many arithmetic operations can only be represented exactly with long fractional parts or cannot be represented exactly at all. Because you necessarily define the fractional length of your fixed-point number or operator, you must designate a rounding mode when performing arithmetic with fixed-point data. The following table describes behavior of each rounding mode.

Rounding Mode Behavior
Round Half to Even Rounds the value to the nearest value that the output type can represent. If the value to round is exactly between two representable values, the even value is chosen so that the least significant bit (LSB) after rounding is zero. This rounding mode has the largest impact on performance but produces the most accurate output values by neutralizing the bias towards higher values that occurs when you perform multiple rounding operations using the Round Half Up mode. In the Round Half to Even mode, any binary value with a least significant bit of zero is even, regardless of its decimal representation. Round Half to Even is the default rounding mode.
Round Half Up Rounds the value to the nearest value that the output type can represent. If the value to round is exactly between two representable values, this rounding mode rounds the value up to the higher of the two valid values, in the positive direction. This rounding mode adds half a least significant bit to the output value and then truncates the value. This rounding mode produces more accurate results but has a larger resource cost than Round Down (truncate).
Round Down (truncate) Rounds the value down toward negative infinity to the nearest value that the output type can represent. The least significant bits of the value are discarded. This rounding mode has the best performance but produces the least accurate output values.

Recently Viewed Topics