Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

Round operator overload

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

class operator Round(const F: TFraction): Int64;

Description

The operator overload enables the Round “operator” or compiler function to operate on a TFraction. The operator rounds the fraction to the nearest whole number value.

Example

var
  F: TFraction;
begin
  F := TFraction.Create(17, 3);
  Assert(Round(F) = 6);
  F := TFraction.Create(-17, 3);
  Assert(Round(F) = -6);
  F := TFraction.Create(-58, 7);
  Assert(Round(F) = -8);
  F := TFraction.Create(3, 1);
  Assert(Round(F) = 3);
  F := TFraction.Create(-3, 1);
  Assert(Round(F) = -3);
  F := TFraction.Create(0, 1);
  Assert(Round(F) = 0);
end;

See Also