Hi All,
i am trying to convert double to string in MQL5, the NormalizeDouble is such a failure as it get numbers such as 0.07000000000000001 and 0.9399999999999999
i have created the below function, but it can only filter our cases as 0.9399999999999999, but fails with 0.07000000000000001
double RNormalizeDouble(double val, int places){
int index = StringFind(val, ".");
string substring = StringSubstr(val, index, places+1);
if(StringGetCharacter(substring, StringLen(substring)-1) == "0"){
substring = StringSubstr(substring, 0, StringLen(substring)-2);
}
Print("Debug ",substring);
string WholeNum = StringSubstr(val, 0, index-1);
string res = WholeNum + substring;
return StringToDouble(res);
}
Sample of the output
PN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
LM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
FE 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
II 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
JP 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
EN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
MN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
RE 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
PD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
EM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.79
QL 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .79
LG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.79
PG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.63
JO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .63
JP 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.63
NF 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.64
RG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .64
EG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.64
DO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.34
EO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .34
DD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.34
DD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.35
RM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .35
GM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.35
KR 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.06
HJ 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .06
NJ 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.06
FL 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.07000000000000001
QN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .07
EG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.07000000000000001
``