I need to compare the integer part of two doubles for inequality and I'm currently doing this:
int iA = (int)dA;
int iB = (int)dB;
if( iA != iB )
{
...
}
but I wonder if there's a better approach than this.
Thanks.
If I used Math.Truncate() instead of a cast to int, would it still be accurate to compare the two resulting double values for equality?
About the hungarian notation comments:
I never use HN myself, not at least in the way most of people do. But this is one of these rare cases where the semantic of a variable directly relates to its type. I could have chosen another syntax like A_As_Integer and B_As_NonInteger but what would have been the difference then?