# why is this divide calculation returning me 0?

float Percentage ;
int CountFalsed = 0;
int Falsed = 0;

``````Percentage = ( (1-0) /121) /1; // means if everything is true I'm giving 0.008% to each 121 slot if it's falsed I'm giving more %
Debug.Log("" + Percentage);
``````

I went so far to the obvious

``````Percentage = (1/2);
``````

returned me same 0

but when I give it

``````Percentage = (2/1);
``````

returns me 2 at last …

``````Percentage = (2*0.5);
``````

gives me 1 at last

what’s the calculation I do not understand here?!?!?

Because you divide with integer values so it’s an integer division. An integer division always returns an integer. the fractional part is always trucated. So 1 / 2 = 0.5 → 0

You need to use float values. When you divide by constant numbers use a float literal:

``````int V = 10;
float P = V / 100.0f;    // P will be 0.1f
``````

If you want to divide two integers and want a fractional part you have to cast one of the operands into a float:

``````int V = 10;
int D = 100;
float P1 = V / D;           // P1 will be 0.0f
float P2 = (float)V / D;    // P2 will be 0.1f
``````

This worked for me:

`````` int A = 10;
int B = 100;

float P1 = A / B;             // P1 will be 0 int
float P2 = (A * 1.0f / B);    // P2 will be 0.1f
``````

Awesome, thanks !