Round the number / Remainder division
-
Hi everyone,
I've been trying to find information on two specific topics but couldn't locate any relevant blocks.
Rounding a variable:
I'm interested in rounding a number stored in a variable. Is it possible to achieve this using custom MQL code, or are there other ways to do it?Performing remainder division in custom MQL code:
I have three variables named "First," "Second," and "result." I'm trying to find a way to calculate the remainder of the division between "First" and "Second" and store the result in the "result" variable. Could someone please guide me on how to write "First % Second" in "result"?Thank you so much for your help in advance!
-
Yes it's possible something like this will put the result in to the variable, if (First>Second) {result=First-Second}
else {result=Second-First;}This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);
-
@jstap add on brother jstap, i can share some example
DoubleToString(AccountEquity(),2)This will round the result number into 2decimal. If you need 3 decimal, use DoubleToString(AccountEquity(),3)
-
@jstap said in Round the number / Remainder division:
Yes it's possible something like this will put the result in to the variable, if (First>Second) {result=First-Second}
else {result=Second-First;}This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);
Would you please check below project regarding remainder of division between 2 variables. I copied the code in "custom mql code" block but it didn't work.
Also I guess the code passes first minus second & vice versa but I need remainder of division between 2 variables. Example: remainder of division between 10 & 4 is 2.
https://fxdreema.com/shared/PwUgOSQlb -
@jstap said in Round the number / Remainder division:
This code will cut the number of 0.000 from the decimel, DoubleToString(variable,2);
@Pheaktra-Capo said in Round the number / Remainder division:
@jstap add on brother jstap, i can share some example
DoubleToString(AccountEquity(),2)
This will round the result number into 2decimal. If you need 3 decimal, use DoubleToString(AccountEquity(),3)Also this code doesn't work when I add it to "custom mql code" block.
could you check below project & guide me what is the mistake:
https://fxdreema.com/shared/4AcP0ko3b -
You just need to add the semi colon:

-
@jstap said in Round the number / Remainder division:
You just need to add the semi colon:

Thanks a lot. another problem is the result of variable "numbers" through the comment block is the same as before & not affected by custom mql code.
How can I replace the result of DoubleToString(numbers,2); to "numbers" variable? -
How do you mean?
-

-
This is how it work
-
No need Custom MQL block. Use Pass block instead of Custom MQL block. Put the DoubleToString in Text(code input)
-
@Pheaktra-Capo Thank you. It solved my problem.
-
Final results are:
1-For rounding a variable:
Use code : DoubleToString(variable,2);
2- For finding remainder division
Use code: MathMod(variable1,variable2);For using codes in block: Use "Value" & "Text(code input)"
Thanks everyone for helping me.