Search Google for "forum.mql4.com formatting numbers commas" or something along those lines.
IIRC, this question was asked before and two really good programmers provided their versions of how to do it. Search Google for "forum.mql4.com formatting numbers commas" or something along those lines.
Thanks - google searches - personalized on or off - appear to becoming narrower by the day. Numerous variations of search phrases used return the same results.
Here is one I have come across since
formatDouble
string formatDouble(double number, int precision, string pcomma=",", string ppoint=".") { string snum = DoubleToStr(number,precision); int decp = StringFind(snum,".",0); string sright = StringSubstr(snum,decp+1,precision); string sleft = StringSubstr(snum,0,decp); string formated = ""; string comma = ""; while (StringLen(sleft)>3) { int length = StringLen(sleft); string part = StringSubstr(sleft,length-3,0); formated = part+comma+formated; comma = pcomma; sleft = StringSubstr(sleft,0,length-3); } if (sleft!="") formated = sleft+comma+formated; if (precision>0) formated = formated+ppoint+sright; return(formated); }
Looks kind of similar to one within the link above.
Yes - they all do - to be honest, my level of put two-and-two together does not qualify to comment as I do not know specifically how they are similar or differ - but it will be interesting comparing code and researching an understanding.
In the meantime I will have a jolly time compiling and testing in the morning.
Thanks - google searches - personalized on or off - appear to becoming narrower by the day. Numerous variations of search phrases used return the same results.
Here is one I have come across since
formatDouble
- formatDouble, copied and pasted from sources, was found missing a line of code resulting in negative numbers being formatted as -,xxx.00 i.e. -,123.45.
The below code rectifies the above incorrect formatting.
formatDouble
string formatDouble(double number, int precision, string pcomma=",", string ppoint=".") { string snum = DoubleToStr(number,precision); int decp = StringFind(snum,".",0); string sright = StringSubstr(snum,decp+1,precision); string sleft = StringSubstr(snum,0,decp); string formated = ""; string comma = ""; while (StringLen(sleft)>3) { int length = StringLen(sleft); string part = StringSubstr(sleft,length-3,0); formated = part+comma+formated; comma = pcomma; sleft = StringSubstr(sleft,0,length-3); } if (sleft=="-") comma=""; // this line missing previously if (sleft!="") formated = sleft+comma+formated; if (precision>0) formated = formated+ppoint+sright; return(formated); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
Besides Hanover's (free) Handy Utility - NumberToStr() - is there any other way to format numbers so that thousands and millions etc are automatically separated by commas, ie. 1,000,000.
Handy Utility - NumberToStr() accomplishes said objective but poses problems to lengthy to go into.
Thank in advance.