Math with floats and integers
#1

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).
Reply
#2

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.
Reply
#3

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.
Reply
#4

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

new currentBizPrice = eStats[i][bizPrice];

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)