I have a float variable and would like to get only the part after the comma, so if I have 3.14. I would like to get 14 as an integer. How can I do that?
Actually all solutions until now are wrong as they don't consider that using Math.Floor()
will do the wrong thing if the value is negative (e.g. Math.Floor(-2.8) -> -3)
double number = -1234.56789;
decimal numberM = Convert.ToDecimal(number);
decimal fraction = Math.Abs(numberM - Math.Truncate(numberM));
int mantissa = Convert.ToInt32((double)fraction * Math.Pow(10, fraction.ToString().Length - 2));