SA-MP Forums Archive
Math with floats and integers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Math with floats and integers (/showthread.php?tid=483396)



Math with floats and integers - Hansrutger - 25.12.2013

So on the last line below it says "tag mismatch" and I don't know why. In theory this would work. :/

Код:
new currentBizPrice = eStats[i][bizPrice];
			
new Float:bizTax;
bizTax = float(gStats[govPercentageBiz]);
currentBizPrice = (currentBizPrice*(bizTax/100));
gStats[govPercentageBiz] is not the problem, wouldn't think of it being a problem... Think it has something to do with converting floats and stuff. If this is not solved, I assume I will just remake gStats[govPercentageBiz] to become a float instead of being an interger in my ini file. Just weird that it doesn't work (weird for me at least).


Re: Math with floats and integers - Konstantinos - 25.12.2013

pawn Код:
new
    currentBizPrice = eStats[i][bizPrice],
    bizTax = gStats[govPercentageBiz];
               
currentBizPrice = floatround((currentBizPrice * (bizTax / 100)));
If gStats[govPercentageBiz] is an integer, then why do you want to convert it to float? It is fine.


Re: Math with floats and integers - Hansrutger - 25.12.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new
    currentBizPrice = eStats[i][bizPrice],
    bizTax = gStats[govPercentageBiz];
               
currentBizPrice = floatround((currentBizPrice * (bizTax / 100)));
If gStats[govPercentageBiz] is an integer, then why do you want to convert it to float? It is fine.
I thought you needed to have a method in floatround? :O Also, I was converting it just to test if that worked, I was playing around with different solutions of the case and none worked, this gives no errors at least.

EDIT: Worked by the way.


Re: Math with floats and integers - Konstantinos - 25.12.2013

The method is by default floatround_round. Good to hear that!


Re : Math with floats and integers - [HRD]Mar1 - 25.12.2013

new currentBizPrice = eStats[i][bizPrice];

new Float:bizTax;
bizTax = float(gStats[govPercentageBiz]);
currentBizPrice = currentBizPrice*(bizTax/100);


AW: Math with floats and integers - Nero_3D - 25.12.2013

You dont need floatround, integer multiplication is enough
But if you only use integer you always should multiply first
pawn Код:
new
    bizTax = gStats[govPercentageBiz],
    currentBizPrice = eStats[i][bizPrice]
;
currentBizPrice = (currentBizPrice * bizTax) / 100; // or just without brackets
Even if you wanted to use floats the correct way would be
pawn Код:
new
    bizTax = gStats[govPercentageBiz],
    currentBizPrice = eStats[i][bizPrice]
;
currentBizPrice = floatround((currentBizPrice * (bizTax / 100.0))); // notice the .0, otherwise it's just a integer division