[Tutorial] Modulo Operator
#2

First of all nice explanation, I read whole of the thread and I understood most of it, but you made some errors, you are using
Float tag but you are using %i/%d(Integer/Decimal) placeholder instead of %f (Float), you will also
get an error if you tried and compiled your code.

Error
Code:
error 004: function "operator%(Float:,_:)" is not implemented
Quote:
Originally Posted by Babul
View Post
the modulo operator returns the remainder of 2 integers. for floats, you simply need to reinvent the formula:
pawn Code:
new Float:a = 10.0;
new Float:b = 4.0;
new result=((a/b)-floatround((a/b),floatround_floor))*b;
Deeper Calculations
pawn Code:
3600.0 / 1500.0 = 2.4
floatround of 2.4 = 2.0
2.4 - 2.0 = 0.4
0.4 * 1500.0 = 600.0
Let me elaborate what Babul said, he said the modulo operator returns 2 (two) remainder of integer
you simply need to change the formala, as shown above.

Fixed Code
pawn Code:
new age, an; //declare a new float and an integer called "an"

an = age % 10; //calculate the age in 10-year anniversary terms (look E1)

if(an == 0) //asks if an is 0 (look E2)
{
    print("Congratulations on your anniversary!");
}
pawn Code:
new minutes, seconds; //declare a new float and an integer (look E1)

seconds = minutes % 60; //calculate modulo (look E2)
minutes = floatround(minutes, floatround_floor); //make the minutes become an integer (look E3)

printf("Time left: %i,%i", minutes, seconds);
- Correct me if I made something wrong.
Reply


Messages In This Thread
Modulo Operator - by Hansrutger - 02.01.2014, 20:02
Re: Modulo Operator - by Patrick - 02.01.2014, 23:25
Re: Modulo Operator - by Hansrutger - 03.01.2014, 00:34
Re: Modulo Operator - by Sawalha - 03.01.2014, 05:52
Re: Modulo Operator - by Vince - 03.01.2014, 10:28
Re: Modulo Operator - by Hansrutger - 03.01.2014, 12:53
Re: Modulo Operator - by newbie scripter - 03.01.2014, 15:18
Re: Modulo Operator - by [CG]Milito - 03.01.2014, 15:56
Re: Modulo Operator - by Battlezone - 29.07.2015, 21:05

Forum Jump:


Users browsing this thread: 1 Guest(s)