You need to format a number for printing with commas (or other locale-dependant marks) in the appropriate places. This is important for creating human-legible print copies of reports.
Use the Perl-compatible regular expression engine to insert the commas where needed. It's simplest to reverse the string prior to the regexp-pass so that we can hop over any decimal portion. Then reverse the string back on return.
While this function works, it would be better if it checked the types of its input arguments to deal with the case of an input string, or someone passing the separator parameter as a character (rather than a string).
Here's an example of partition-number in action: