Rounding numbers in MT4 via NormalizeDouble - page 5

 
Dmitry Fedoseev:

Here is your code:

Put 3 instead of 2 and it's 0.036

It worked! Thank you. I normalise to 3 and then trim the extra digits after the decimal point.

Can you tell me, is there a standard function to trim H digits after the comma? Like StringSubStr only if it is a fractional number.

 
Roman Starinskij:

That's how it works! Thank you. I normalise to 3 digits and then trim the extra digits after the decimal point.

Can you tell me if there is a standard function to trim H digits after the decimal point? Like StringSubStr only if it is a fractional number.

If you want to trim digits when displaying them on the screen (log), there is DoubleToString() for that.
 
Ihor Herasko:
If you're talking about trimming digits when outputting to the screen (log), then DoubleToString() is for that.

No. DoubleToString works just like NormalizeDouble().

 
Roman Starinskij:

That's how it works! Thank you. I normalise to 3 digits and then trim the extra digits after the decimal point.

Can you tell me if there is a standard function to trim H digits after the decimal point? Like StringSubStr only if it is a fractional number.

There is no such function, as it is not needed. Your calculator is wrong.
 
Roman Starinskij:

Can you tell me if there is a standard function to truncate H digits after the decimal point? Like StringSubStr only if it is a fractional number.

I use one, but it's 'non-standard':

//+------------------------------------------------------------------+
//| Double Crop function                                             |
//+------------------------------------------------------------------+
double DoubleCrop(double value,int crop)
  {
   string ValueToString="";
   ValueToString=DoubleToString(value,crop);
   return StringToDouble(ValueToString);
  }
//+------------------------------------------------------------------+
 
lilita bogachkova:

I use one, but it's 'custom':

What's the genius move?

string ValueToString="";
   ValueToString=DoubleToString(value,crop);
 
lilita bogachkova:

I use one, but it's 'out of the box':

Just wrote, DoubleToString doesn't trim, it works the same way as NormalizeDouble - it rounds. No... we're on a bulldozer.
 

A glitch is detected:

   Alert(
         DoubleToStr(1.15,1)+" "+
         DoubleToStr(1.25,1)+" "+
         DoubleToStr(1.35,1)+" "+
         DoubleToStr(1.45,1)
         );

Result: 1.1 1.3 1.4 1.5

With 1.15 there was a discard and with steel numbers there was a rounding.

 
Dmitry Fedoseev:

A glitch is detected:

Result: 1.1 1.3 1.4 1.5

With 1.15 there was a discard and with steel numbers there was a rounding.

Yes, I must admit using it without checking the result :(((
 

Until the developers remove

it

StringLen

The number of characters in the string, not including the trailing zero.

there is nothing you can do about the truncation.