Question: I need a way to format numbers. I stored some numbers in my DB table, e.g. `12500`, and would like to print them in this format `12 500` (so there is a space every 3 digits). Is there an elegant way to do this?

Answer: 
see: <http://www.justskins.com/forums/format-number-with-comma-37369.html>

there is no built in way to it ( unless you using Rails, ActiveSupport Does have methods to do this) but you can use a Regex like 

```
formatted_n = n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse

```
I'm aware this is an old question but.

why not just use a substring substitution.

in pseudo code....

```
String numberAsString = convertNumberToString(123456);
int numLength = V.length;//determine length of string

String separatedWithSpaces = null;

for(int i=1; i<=numlength; i++){//loop over the number
separatedWithSpaces += numberAsString.getCharacterAtPosition(i);
    if(i.mod(3)){//test to see if i when devided by 3 in an integer modulo,
    separatedWithSpaces += " ";

    }//end if

}//end loop

```

I know it isn't in any particular languange, but hopefully you get the idea.

David