Q:

Correct way for get fractional part double like int

I need get fractional part of double like int and only two numbers. My code
(int)Math.Floor(val * 100 - (int)val * 100)

but this can (int)val * 100 may be out of range of int or long. Ok. 
If i try  
(int)Math.Floor((val - (int)val) * 100)

Return value may be incorrect. For example:
double val = 56.9;
int retVal = (int)Math.Floor((val - (int)val) * 100);
// retVal = 89, because (val - (int)val) return 0.899999999675

How correct get fractional part of double like int?

A:

Try this extensions method:
public static int GetFrac2Digits(this double d)
{
    var str = d.ToString("0.00", CultureInfo.InvariantCulture);
    return int.Parse(str.Substring(str.IndexOf('.') + 1));
}

