Round digit (MQL4)

 
Hi there, 

Is there anyway to round 0.001 to 0.01? 

Eg : 0.012 to 0.02. 

I tried round (); 
Unfortunately it only round up 5 and above. 

Thanks in advance. 
 

Hi and good morning,

in my opinion there is no MQL function for your requirement. But you can
use MathCeil() for that. E.g. (for 2 digits):

value = MathCeil(value * 100.0) / 100.0;

Best regards

 
Lee Su Keat: Is there anyway to round 0.001 to 0.01? Eg : 0.012 to 0.02. I tried round (); Unfortunately it only round up 5 and above.

Yes, use ceil() / MathCeil(). There is round(), floor() and ceil(). It helps to read the documentation ... https://www.mql5.com/en/docs/math

Example:

double
   dblValue   = 0.012,
   dblCeiling = ceil( dblValue / 0.01 ) * 0.01;

PrintFormat("Value = %f; Ceilling = %f", dblValue, dblCeiling);
2021.07.17 07:58:16.757 Test EURUSD,H1: Value = 0.012000; Ceilling = 0.020000
Documentation on MQL5: Math Functions / MathCeil
Documentation on MQL5: Math Functions / MathCeil
  • www.mql5.com
MathCeil - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Werner Klehr:

Hi and good morning,

in my opinion there is no MQL function for your requirement. But you can
use MathCeil() for that. E.g. (for 2 digits):


Best regards

Fernando Carreiro:

Yes, use ceil() / MathCeil(). There is round(), floor() and ceil(). It helps to read the documentation ... https://www.mql5.com/en/docs/math

Example:

Thank you. ceil() is works. 

Thanks. 


Have a good weekend. =D

 
Lee Su Keat: Thank you. ceil() is works. Thanks. Have a good weekend. =D
You are welcome!
Reason: