If you don’t add .0f it will be treated like it is an integer, and an integer division is a lot different from a floating point division indeed 🙂
float percent = (n * 100.0f) / v;
If you need an integer out of this you can of course cast the float or the double again in integer.
int percent = (int)((n * 100.0f) / v);
If you know your n value is less than 21474836 (that is (2 ^ 31 / 100)), you can do all using integer operations.
int percent = (n * 100) / v;
If you get NaN is because wathever you do you cannot divide for zero of course… it doesn’t make sense.