Rounding a floating-point number.

 

Rounding uses Banker's algorithm when half of the value causes rounding to an even number.
 

  • 12.4 rounds to 12;
  • 12.5 rounds to 12;
  • 12.6 rounds to 13.

 

Syntax

function Round(x: extended): integer;

 

Parameters and return values

Parameter

Type

Value

x

extended

fractional number that you need to round.

 

Function result

Integer value.

 

Example


begin
  mLogScript('Round(12.4) = ' + inttostr(round(12.4)), '');
  mLogScript('Round(12.5) = ' + inttostr(round(12.5)), '');
  mLogScript('Round(12.6) = ' + inttostr(round(12.6)), '');
end.


Script work result

[09:03:22] (Log "Round"): Round(12.4) = 12

[09:03:22] (Log "Round"): Round(12.5) = 12

[09:03:22] (Log "Round"): Round(12.6) = 13
 

See also

IntToStr
mLogScript