Because what you done is here integer division. If a
and b
are integer and a < b
, a / b
always give you 0
as a result regardless which type you assign it or cast it.
In your cause, a
is probably less than 800
so that's why it gives 0
as a result.
.NET has 3 type of division. From 7.7.2 Division operator
- Integer division
- Floating-point division
- Decimal division
From Integer division part;
The division rounds the result towards zero, and the absolute value of
the result is the largest possible integer that is less than the
absolute value of the quotient of the two operands.
From / Operator (C# Reference)
When you divide two integers, the result is always an integer. For
example, the result of 7 / 3 is 2. To determine the remainder of 7 /
3, use the remainder operator (%). To obtain a quotient as a rational
number or fraction, give the dividend or divisor type float or type
double.
As a solution, you can cast double your a
or 800
like;
b = ((double)a / 800 * 100);
or
b = (a / 800d * 100);