Precision loss in calculation

Try

percentage = ((float) value / ((float) gAVG * 2.0))*100.0;

This will take more time and code space for the floating point emulation, but it'll work.

You could also try

percentage = (value * 100) / (gAVG * 2);

which is mathematically equivalent to your first expression but reorders the operations in such a way to avoid the problem you see. It will still have integer rounding issues, but it avoids the computational penalty for floating point calculations.

-j