Frac Function

Applies to TestComplete 15.64, last modified on June 12, 2024

The Frac function returns the fractional part of a number.


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


Returns the fractional part of the specified value.


The function has the following parameter:


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.


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.


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

See Also

DelphiScript Routines
Int Function

Highlight search results