I can't understand what is wrong? I have a little variable.
decimal Price = 22348 / 100;
The answer I get is: 223, but I should get 223.48. What is the problem?
I can't understand what is wrong? I have a little variable.
decimal Price = 22348 / 100;
The answer I get is: 223, but I should get 223.48. What is the problem?
What you are doing is this:
decimal = (decimal)(int / int);
So you are calculating integers (yielding the result you get) and then convert the outcome to a decimal.
Instead, you could cast either of the operands to a decimal:
decimal Price = 22348 / 100M;
Declare those numbers as decimal variable then put the divisions result in the other decimal variable.
decimal num1 = 22348;
decimal num2 = 100;
decimal Price = (num1 / num2);
Console.WriteLine(Price);
This will give the result 223.48