MT4(MQL4)/MT5(MQL5)のStringToDouble
シンボル表現を含むstring型の文字列を double 型の数値に変換します。
double StringToDouble(
string value // 文字列
);
シンボルと言っても、要はプラスマイナスですね。(ちゃんと言うなら浮動小数点数とか言わないといけないのでしょうが)
MT4→MT5になっても、変わらず使えます。
サンプルコード
void OnInit()
{
string teststring = 123.0 ;
StringToDouble(teststring);
Print("teststring = ",teststring,",StringToDouble(teststring) = ",StringToDouble(teststring));
Print("teststring + teststring = ",teststring+teststring);
Print("StringToDouble(teststring) + StringToDouble(teststring) = ",StringToDouble(teststring)+StringToDouble(teststring));
string teststring2 = -123.0 ;
StringToDouble(teststring2);
Print("teststring2 = ",teststring2,",StringToDouble(teststring) = ",StringToDouble(teststring2));
Print("teststring2 + teststring2 = ",teststring2+teststring2);
Print("StringToDouble(teststring2) + StringToDouble(teststring2) = ",StringToDouble(teststring2)+StringToDouble(teststring2));
return;
}
結果
teststring = 123,StringToDouble(teststring) = 123.0
teststring + teststring = 123123
StringToDouble(teststring) + StringToDouble(teststring) = 246.0
teststring2 = -123,StringToDouble(teststring) = -123.0
teststring2 + teststring2 = -123-123
StringToDouble(teststring2) + StringToDouble(teststring2) = -246.0
【参考】MQL5公式ページ
コメント / Comments