roundedTo

roundedTo(decimalPlaces: Integer): Real;

The roundedTo method of the Real primitive type returns the receiver rounded to the number of decimal places specified in the decimalPlaces parameter.

The following example shows the use of the roundedTo method.

vars
    realValue : Real;
begin
    realValue := 340.5;                   // Defines the variable value
    realValue := (realValue / 27).roundedTo(2);
    write realValue;                      // Outputs 12.61
    realValue := 340.5;                   // Redefines the variable value
    realValue := (realValue / 27).roundedTo(5);
    write realValue;                      // Outputs 12.61111
end;

As Real values are implemented as floating point values, rounding may not return the expected value.