詳しくは是非この記事(クリックで記事に飛べます)をご参照いただければと思いますが、このツールを作成する際にいちばん困ったのが、意外にも3桁区切り表示をできるようにすることでした。

↑みにくいですが、証拠金とか確定利益の表示とかですね。
こういう表示の仕方って、アルゴリズムを使って変換しようとすると結構頭の体操になったりします。
たぶん実現方法は無数にあるかと思いますが、私はこんな感じで関数を切り出して作ってみました。
-----
string addcomma(double inputdata, int dig)
{
string returnstr = DoubleToStr(inputdata,dig);
int length;
int noofcomma;
int firstcomma;
length = StringLen(DoubleToStr(MathFloor(inputdata),0));
if (inputdata >= 0) noofcomma = (int)MathFloor((length - 1) / 3);
else noofcomma = (int)MathFloor((length - 2) / 3);
if (noofcomma == 0) return (returnstr);
firstcomma = length - noofcomma * 3;
if (firstcomma == 0) firstcomma = 3;
for (int i = 0; i < noofcomma; i++){
returnstr = StringConcatenate(StringSubstr(returnstr, 0, firstcomma + i * 4),",",StringSubstr(returnstr, firstcomma + i * 4));
}
return (returnstr);
}
-----
使い方はDoubleToStrと同じで、
string display = addcomma(表示させたい数値(double指定), 小数点以下桁数(整数指定))
というような感じで使えるかと思います(ほとんど使う機会は無いと思いますがwww)。
割とシンプル化してみたつもりですが・・・どうでしょうかね。
もし実現方法に困っていたら、是非使ってみてください。(バグが潜んでいるかもしれません・・・)