[Solved] Convert decimal to integer without losing monetary value


decimal firstDecimal = 120.01M;
double firstDouble = 120.01;
float firstFloat = 120.01F;

Console.WriteLine ((int)(firstDecimal * 100)); // 12001
Console.WriteLine ((int)(firstDouble * 100));  // 12001
Console.WriteLine ((int)(firstFloat * 100));   // 12001

Console.WriteLine (Convert.ToInt32(firstDecimal * 100)); // 12001
Console.WriteLine (Convert.ToInt32(firstDouble * 100));  // 12001
Console.WriteLine (Convert.ToInt32(firstFloat * 100));   // 12001

This means one thing…. you have something else going wrong with your code.

EDIT:
Convert.ToInt32 produces the exact same result

2

solved Convert decimal to integer without losing monetary value