Frac Function

Applies to TestComplete 15.47, last modified on January 20, 2023

The Frac function returns the fractional part of a number.

Declaration

Frac(FloatValue) Parameters
FloatValue [in] Required Float
Result     Float  

Description

Returns the fractional part of the specified value.

Parameters

The function has the following parameter:

FloatValue

Specifies the float value that must be processed.

Return Value

A float value that holds the fractional part of the argument. If FloatValue is empty, Frac returns 0.

Remarks

In some situations, the Frac function may return a value that differs from the real fractional part of an argument. For example:

  • Frac(236113.5) returns 0.5
  • Frac(2361.135*100) returns 0.500000000029104 (while we expect it returns 0.5).

The problem occurs due to certain specifics of storing floating-point numbers in memory. To avoid the problem, you can use the following SmartFrac function. Its value parameter specifies the floating-point value to be processed. The digits parameter specifies the desired number of decimal places in the resultant value.

DelphiScript

function SmartFrac(value, digits);
var
  n, i;
begin
  n := 1;
  for i := 1 to digits do
    n := n * 10;
  Result := Round(Frac(value) * n) / n;
end;

See Also

DelphiScript Routines
Int Function

Highlight search results