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.)
invocation
editSetRoundMode 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):
rmNearest- rounds to the nearest even integer (Banker‘s Rounding:
0.5rounds down to0;1.5rounds up to2). This is the default. rmDown- generally rounds to the next smaller integer
rmUp- generally rounds to the next larger integer
rmTruncate- 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.
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.