Reputation: 2633
Is That Any calculation or method allow me to check whether a double value is Int or Double in c# code
Example
Double NumberOne = 55.00 // Return False
Double NumberTwo = 55.10 // Return True
Upvotes: 2
Views: 336
Reputation: 526
private bool IsDoubleNotAnInt(double num)
{
if ((num % 1) == 0)
{
return false;
}
else
{
return true;
}
}
Upvotes: 3
Reputation: 3358
You could compare it with value without fractional part:
Math.Floor(n) != n
Upvotes: 1
Reputation: 33553
Use Math.Floor
if (Math.Floor(number) == number) {
// yay, an "int"
}
Upvotes: 4