Search code examples
type-conversionformatdoublemql4normalize

StrToDouble, NormalizeDouble, removes last zero from double type


I have this string str = "1.52220";

And i want to send an Order with this price. I need to convert it in Double.

So when i convert it to double using StrToDouble, it removes last 0 and return this 1.5222 and OrderSend function is not accepting this value, it is return 130 error because amount of digits after decimal points are not normalized.

So then i try: NormalizeDouble(StrToDouble(str), digits) but also not working, not added last zero.

I am calculating digits for symbol with this function:

int digits = (int)MarketInfo(symbol, MODE_DIGITS);

and for this example is 5.

double price = NormalizeDouble(StrToDouble(str), digits);

Then value of price is 1.5222 and not 1.52220.

Is there some way to don't remove last zero? or the problem is somewhere else?

Or i have to check if last character in string str is zero and than replace it with 1, then would be value fine. Thank you.


Solution

  • Problem is not with the last zero.

      void OnTick()
      {
         int ticket=OrderSend(_Symbol,OP_BUYLIMIT,0.10,1.00,0,0.99,1.01);
         printf("%i %s: ticket=%d, error=%d",__LINE__,__FILE__,ticket,_LastError);
         ExpertRemove();
      }
    

    logs (latest first):

      2020.05.24 21:14:17.136   2020.05.01 00:00:00  tmpSOF EURUSD,M15: ExpertRemove function called
      2020.05.24 21:14:17.136   2020.05.01 00:00:00  tmpSOF EURUSD,M15: 4 tmpSOF.mq4: ticket=1, error=0
      2020.05.24 21:14:17.135   2020.05.01 00:00:00  tmpSOF EURUSD,M15: open #1 buy limit 0.10 EURUSD at 1.00000 sl: 0.99000 tp: 1.01000 ok