0
2
90k
0
Top 1% !
Refined
Popularity: 26644th place

### Published on:

 Architecture x86_64 InputName0 x InputName1 threshold InputType0 double InputType1 double Language C# MethodName IsInteger OutputType bool Windows Version Windows7

# `IsInteger: Determines whether a number is an integer, given a tolerance threshold.`

```Determines whether a number is an integer, given a tolerance threshold.

<param name="x">The value to be compared.</param>
<param name="threshold">The maximum that the number can deviate from its closest integer number.</param>

<returns>True if the number if an integer, false otherwise.</returns>```
post this code
Copy Embed Code
``` <iframe id="embedFrame" style="width:600px; height:300px;" src="https://www.snip2code.com/Embed/1396093/IsInteger--Determines-whether-a-number-i?startLine=0"></iframe> ```
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
#region Comparison /// <summary> /// Determines whether a number is an integer, given a tolerance threshold. /// </summary> /// /// <param name="x">The value to be compared.</param> /// <param name="threshold">The maximum that the number can deviate from its closest integer number.</param> /// /// <returns>True if the number if an integer, false otherwise.</returns> /// public static bool IsInteger(this double x, double threshold) { double a = Math.Round(x); double b = x; if (a == b) return true; double limit = Math.Abs(a) * threshold; double delta = Math.Abs(a - b); return delta <= limit; }