From Lazarus wiki
Jump to navigationJump to search

Deutsch (de) English (en)

With math.setRoundMode you can set the FPU’s method of rounding. If no FPU is present, the global variable system.softFloat_rounding_mode will determine the rounding mode for floating-point operations implemented by software.

This also affects the run-time behavior of the round function. (Note, constant expressions can and will be evaluated during compile-time, thus the presented techniques do not affect compile-time results.)


SetRoundMode resides in the math unit. You need to include the math unit in the uses clause.

SetRoundMode is a unary function. The function’s signature reads:

function setRoundMode(const roundMode: TFPURoundingMode): TFPURoundingMode

The following values are permissible for roundMode (cf. TFPURoundingMode):

rounds to the nearest even integer (Banker‘s Rounding: 0.5 rounds down to 0; 1.5 rounds up to 2). This is the default.
generally rounds to the next smaller integer
generally rounds to the next larger integer
cuts off the decimal places

The function will return the previous rounding mode, before it was changed. Thus, it returns the same value as math.getRoundMode.


Warning: The setting of the rounding mode applies to all internal floating point calculations. In particular, it determines how numbers that cannot be represented exactly as the native floating-point type’s values are to be rounded to the internal representation within the scope of the available bits. Therefore, the usage of setRoundMode for general rounding purposes is not recommended.

see also