---
url: >-
  /statelake/scripting-reference/functions-and-procedures/numeric-functions/comparevalue.md
---

# CompareValue

The **CompareValue** function returns the relationship between two numeric floating-point values **A** and **B**.

**CompareValue** allows you to specify a maximum difference to use when comparing these two values, so that they will be considered the same if they are within that specified **Epsilon** amount.

**A** and **B** are the values to be compared.

**Epsilon** is the maximum amount by which the values **A** and **B** can differ, while still considered to be the same value.

**CompareValue** returns an integer value, depending on whether the values are considered to match, or not match i.e. where one value is less than the other by the value of Epsilon, and both values are floating-point numbers) -

* If **A** is less than **B** - returns -1
* If **A** is greater than **B** - returns **1**
* If **A** is considered equal to **B** - returns **0** (zero)

**Declaration**: Function CompareValue(const A, B : Double; Epsilon : Double) : Integer;

A few examples are shown below.

```pascal
procedure ScriptEvent (var Value : variant);
var
    ValA, ValB, ValC : double;
    ValD : integer;
begin
  LogInfo('');
  ValA := 12.0;
  ValB := 25.05;
  ValC := 5.0;
  ValD := CompareValue(ValA, ValB, ValC);                      //returns -1(N)
  LogInfo(IntToStr(ValD));
  LogInfo('');
  LogInfo(IntToStr(CompareValue(12.1,25.1,5.5)));              // returns -1(N)
  LogInfo(IntToStr(CompareValue(8.5, 9.4, 1)));                // returns 0(Y)
  LogInfo(IntToStr(CompareValue(10.8, 8.8, 1.5)));             // returns 1(N)
  LogInfo(IntToStr(CompareValue(20.397, 30.2223, 8.5)));       // returns -1(N)
  LogInfo(IntToStr(CompareValue(20.397, 30.39, 10.0)));        // returns 0(Y)
  LogInfo(IntToStr(CompareValue(20.5, 30.5, 11)));             // returns 0(Y)
  LogInfo(IntToStr(CompareValue(30, 20, 5)));                  // returns 1(N)
  LogInfo(IntToStr(CompareValue(8, 10, 1)));                   // returns -1(N)
  LogInfo(IntToStr(CompareValue(12.56, 18.71, 6)));            // returns -1(N)
  LogInfo(IntToStr(CompareValue(20, 30, 11)));                 // returns 0(Y)
  LogInfo(IntToStr(CompareValue(20, 30, 9)));                  // returns -1(N)
  LogInfo(IntToStr(CompareValue(18.71, 12.56, 6)));            // returns 1(N)
  LogInfo('');
  LogInfo(IntToStr(CompareValue(20, 22, 0)));                 // returns -1(N)
  LogInfo(IntToStr(CompareValue(22, 20, 0)));                 // rreturns 1(N)
  LogInfo(IntToStr(CompareValue(8.5, 8.6, 0)));               // returns -1(N)
  LogInfo(IntToStr(CompareValue(8.5, 8.5, 0)));               // returns 0(Y)
  LogInfo('');

end;
```
