system
1
i am making labels to show a percentage calculated using instance variables
public int two = 32;
public int deck; //assume has a value assigned in code
GUI.Label(new Rect(50, 100, 50, 50), System.Convert.ToString(Calculate(ten)) + “%”);
int Calculate(int card)
{
int total= card/deck*100;
return total;
}
however the label is only displaying 0% any ideas where i’m going wrong?
Card is less than deck, and both are ints. When dividing ints, you get an int back, so for instance 3/4 = 0, 0 * 100 = 0.
Cast to float before dividing, for instance (float)3/4 = 0.75, 0.75 * 100 = 75