Something that a tired me wasted a lot of time on, pursuing horrible algorithms, until my laptop ran out of power and I had to walk home and and I came up with (what I think is a) pretty good way of solving it. This, essentially, formats a number all fancy-like, with commas. Ie:
123456 -> 123,456
12345 -> 12,345 12345.6789 -> 12,345.6789