WholeNumberPart property

Project: Fractions

Unit: DelphiDabbler.Lib.Fractions

Record: TFraction

Applies to: ~>0.1

property WholeNumberPart: Int64;

Description

This property provides the whole number part of a TFraction when considered as a mixed fraction.

For any TFraction it’s WholeNumberPart plus its FractionalPart is equal to the original fraction. I.e. for TFraction F

F = F.WholeNumberPart + F.FractionalPart;

Example

var
  F: TFraction;
begin
  F := TFraction.Create(21, 4);
  Assert(F.WholeNumberPart = 5);  // 21/4 = 5 + 1/4
  F := TFraction.Create(-21, 4);
  Assert(F.WholeNumberPart = -5); // -21/4 = -5 - 1/4
  F := TFraction.Create(5, 11);
  Assert(F.WholeNumberPart = 0);  // 5/11 = 0 + 5/11
  F := TFraction.Create(60, 6);
  Assert(F.WholeNumberPart = 10); // 60/6 = 6 + 0/6
  F := -7;
  Assert(F.WholeNumberPart = -7); // -7/1 = -7 + 0/1
end;

See Also