Alternative for '%' in PAWN
#12

the modulo operator returns the remainder of 2 integers. for floats, you simply need to reinvent the formula:
Код:
new Float:a=10.0;
new Float:b=4.0;
new result=floatround((a/b),floatround_floor)*b;
10.0 / 4.0 = 2.5
round_floor of 2.5 = 0.5
0.5 * 4.0 = 2.0
...looks similar to
10 % 4 = 2

another test: 100.0 % 3.0
100.0/3.0=33.333333
0.333333*3.0=1.000000
100%33=1

oh, i forgot to mention
3600.0/1500.0=2.4
0.4*1500=600
3600.0%1500.0=600

oops i made a mistake there. the floor is NOT the method to round, it takes the main part instead of the small parts... moment. editing post (again) lol

here is the solution: the floatround_floor returns the big part %f.0, subtracted that from the whole number %f, will return the little %.f part:
Код:
new result=((a/b)-floatround((a/b),floatround_floor))*b;
3600.0 / 1500.0 = 2.4
floatround of 2.4 = 2.0 // i forgot this to create the small number...
2.4 - 2.0 = 0.4 //incl. this line..
0.4 * 1500.0 = 600.0

did i miss something again?
Reply


Messages In This Thread
Alternative for '%' in PAWN - by Jochemd - 01.06.2012, 09:31
Re: Alternative for '%' in PAWN - by Vince - 01.06.2012, 09:40
Re: Alternative for '%' in PAWN - by Jochemd - 01.06.2012, 09:44
Re: Alternative for '%' in PAWN - by MP2 - 01.06.2012, 09:51
Re: Alternative for '%' in PAWN - by Vince - 01.06.2012, 09:58
Re: Alternative for '%' in PAWN - by Jochemd - 01.06.2012, 09:58
Re: Alternative for '%' in PAWN - by MP2 - 01.06.2012, 10:02
Re: Alternative for '%' in PAWN - by Jochemd - 01.06.2012, 10:04
Re: Alternative for '%' in PAWN - by MP2 - 01.06.2012, 10:06
Re: Alternative for '%' in PAWN - by MadeMan - 01.06.2012, 10:07
Re: Alternative for '%' in PAWN - by Vince - 01.06.2012, 10:29
Re: Alternative for '%' in PAWN - by Babul - 01.06.2012, 10:29
Re: Alternative for '%' in PAWN - by MadeMan - 01.06.2012, 10:36

Forum Jump:


Users browsing this thread: 3 Guest(s)