This Maths is wrong? or the Code?
#5

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
pawn Код:
new Float:percent;
//new percent; // Tried with both Float and this one...
percent = (playerStats[playerid][pGunSkill]/50)*100;
Whats wrong with that? It just shows up as 0.00000 (or just 0 with the non Float Number)...
Your maths is pretty much correct based on the information given, except that you should divide by 49 if you have a max of 49. However, that's not what's causing the problem: it looks like pGunSkill is an integer rather than a float, which is causing your division to spit out an integer:

integer / integer = integer

Integers have the numbers after their decimal point truncated (cut off), so 0.9, 0.333, 0.4 etc. would become 0. That also means any value of the calculation 'playerStats[playerid][pGunSkill]/50' would become 0 since pGunSkill is always lower than 50.

In order to fix it you can do two solutions:
  • Skip the division and do what Babul suggested. Probably what I'd suggest except you would not get anyone with 100% -- to get 100% then multiple by 2.04081633 (100/49) instead, since your maximum value is 49.
  • Change the '50' to '50.0' and '100' to '100.0' OR use floatdiv and floatmul. You may also need to use float(playerStats[playerid][pGunSkill]) to convert the gun skill to a float making it pure float multiplication/division (I can't remember how Pawn copes with mixed ints/floats)
Reply


Messages In This Thread
This Maths is wrong? or the Code? - by DarrenReeder - 15.10.2010, 19:29
Re: This Maths is wrong? or the Code? - by Calgon - 15.10.2010, 19:48
Re: This Maths is wrong? or the Code? - by DarrenReeder - 15.10.2010, 20:00
Re: This Maths is wrong? or the Code? - by Babul - 15.10.2010, 20:39
Re: This Maths is wrong? or the Code? - by Simon - 15.10.2010, 21:43

Forum Jump:


Users browsing this thread: 3 Guest(s)