This function takes a number as a char array and inserts commas in the right places; "1000" becomes "1,000," etc; for numbers smaller than that, it just returns the original.
char[] formatNumber(char[] n)
{
char[] number=n.dup;
for(int i=n.length-3; i>1; i-=3)
{
if(!std.ctype.isdigit(number[i]))
throw new StringException("expected digits:"~n);
else
number=number[0..i-1]~","~number[i..$];
}
return number;
}
unittest
{
assert(formatNumber("100")=="100");
assert(formatNumber("1000")=="1,000");
assert(formatNumber("10000000")=="10,000,000");
}

--
 
 
Ameer
---
Visit my blog at
http://ameerarmaly.blogspot.com
---
Life is either tragedy or comedy.
 Usually it's your choice. You can whine or you can laugh.
--Animorphs