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.

IsWholeNumber method

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

function IsWholeNumber: Boolean;

Description

The IsWholeNumber method checks if a TFraction instance represent a whole number and returns True if so or False if not.

When a fraction is a whole number its numerator is an exact integer multiple of its denominator.

Example

var
  F: TFraction;
begin
  F := TFraction.Create(-2, 2);  // F = -2/2 = -1 - 0/2 = -1
  Assert(F.IsWholeNumber);
  F := TFraction.Create(12, 4);  // F = 12/4 = 3 + 0/4 = 3
  Assert(F.IsWholeNumber);
  F := TFraction.Create(7, 4);   // F = 7/4 = 1 + 3/4
  Assert(not F.IsWholeNumber);
  F := 42;
  Assert(F.IsWholeNumber);       // F = 42/1 = 42 + 0/1 = 42
  F := 0;
  Assert(F.IsWholeNumber);       // F = 0/1 = 0 + 0/1 = 0
end;

##= Note

Another test for a whole number fraction is to check whether its FractionalPart property is equal to 0. If this property is zero then the fraction is a whole number.

See Also