Formatting numbers in D7
There is a format_number API module, which may eventually handle this for you. And possibly will make it into D8.

For the moment I think the function you are looking for is number_format()