Float arithmetic not returning correct total?

Let’s say I want to split a percentage of a given value across all players based on the total stock they have compared to each other. For this example, the value is 40, and the percentage is 20%, so 8 is to be split across the players. Two players each have 20 stock, and the others do not have stock (40 stock total).

float stockFraction = stock[i] / allStock;
int total = (int)(value * percentage * stockFraction);
Debug.LogFormat("{0} * {1} * ({2} / {3}) = {4}", value, percentage, stocks[i], allStock, (float)(total * percentage * stockFraction));

Whenever I run this batch of code in my game, both players get 40 * 0.2 * (20 / 40) = 0.

However, this math is incorrect, because:

40 * 0.2 * (20/40) = 40 * 0.2 * 0.5 = 40 * 0.1 = 4

I get 0 regardless of whether the value is an int or a float. Is there something I do know about float arithmetic, or am I missing something in my equation(s)?

I figured out the problem.

stock[i] and allStock are both integers, and when generating stockFraction, it first completes the equation, then converts the result into a float. In other words, the equation stock[i] / allStock - consisting of entirely integers - generates an integer (which immediately rounds up/down the result, turning the fraction into 1 or 0), then it is converted into a float.

That is where everything else is multiplied by 0 and becomes 0.