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

Published on:

Architecturex86_64
InputName0x
InputName1threshold
InputType0double
InputType1double
LanguageC#
MethodNameIsInteger
OutputTypebool
Windows VersionWindows7

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>
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; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus