27.01.2019, 15:46
(
Last edited by faxxe; 27/01/2019 at 04:45 PM.
)
I'll write something for you. Just wait some minutes.
Check this out.
This way you can round integers to the next multiple of 10.
Like 5 will be 10, 3 will be 0.
When i divide 3 with 10, we'll have a remainder rem.
Using the mathematic principles of the euclidean division we can do it like this.
So a function can look like that.
So let's check this out.
We have our number 25.
25 / 10 = 2,5, alright we don't use it here, but it's important to understand.
We do 25 % 10 = 5, thats our remainder.
Now we check, is our remainder rem more than 5 or equal?
Our remainder is 5, so we'll subtract the remainder from our number and we'll add 10.
Means 25-5 = 20. 20+10 = 30. That's the math behind it.
Check this out.
This way you can round integers to the next multiple of 10.
Like 5 will be 10, 3 will be 0.
When i divide 3 with 10, we'll have a remainder rem.
Using the mathematic principles of the euclidean division we can do it like this.
Code:
#include <a_samp> main() { new num = 5; new rem = num % 10; printf("%d",rem >= 5 ? (num - rem + 10) : (num - rem)); }
Code:
round(num) { new num = 5; new rem = num % 10; return rem >= 5 ? (num - rem + 10) : (num - rem); }
We have our number 25.
25 / 10 = 2,5, alright we don't use it here, but it's important to understand.
We do 25 % 10 = 5, thats our remainder.
Now we check, is our remainder rem more than 5 or equal?
Our remainder is 5, so we'll subtract the remainder from our number and we'll add 10.
Means 25-5 = 20. 20+10 = 30. That's the math behind it.