I have this value 0.004499807884787987
I want only 0.0044
what math function should use
thanks
double abc= 0.004499807884787987; string abc1=StringSubstr(DoubleToStr(abc,10),0,6); Print("String: ",abc1, " Double: ",string(abc1), " NormalizeDouble: ",NormalizeDouble(abc,4));
DoubleToString and
StringToDouble
I have this value 0.004499807884787987
I want only 0.0044
what math function should use
thanks
string valueStr = DoubleToString(0.004499807884787987,10);//10 digits or could be anything more than 4
string newStr = StringSubstr(valueStr, 0, 6);
double valInDoubls = StringToDouble(newStr);// this will give you value 0.0044
string backInStr = DoubleToStr(valInDoubls,4);//Convert for printing purpose
Print("NewVal - "+newStr+" valInDoubls : "+backInStr);
You will see valInDoubls as 0.0044
NewVal - 0.0044 valInDoubls : 0.0044
string valueStr = DoubleToString(0.004499807884787987,10);//10 digits or could be anything more than 4
string newStr = StringSubstr(valueStr, 0, 6);
double valInDoubls = StringToDouble(newStr);// this will give you value 0.0044
string backInStr = DoubleToStr(valInDoubls,4);//Convert for printing purpose
Print("NewVal - "+newStr+" valInDoubls : "+backInStr);
You will see valInDoubls as 0.0044
NewVal - 0.0044 valInDoubls : 0.0044
in this case it can be digits more than 8 for truncation.
string valueStr = DoubleToString(0.004499807884787987,10);//10 digits or could be anything more than 4
string newStr = StringSubstr(valueStr, 0, 6);
double valInDoubls = StringToDouble(newStr);// this will give you value 0.0044
string backInStr = DoubleToStr(valInDoubls,4);//Convert for printing purpose
Print("NewVal - "+newStr+" valInDoubls : "+backInStr);
You will see valInDoubls as 0.0044
NewVal - 0.0044 valInDoubls : 0.0044
In fact it is same as solution provided by Mehmet Bastem but there was error. It should have been
NormalizeDouble(abc1,4)
MathFloor(0.004499807884787987*10000)/10000;
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have this value 0.004499807884787987
I want only 0.0044
what math function should use
thanks