External plugins (and also Moodle core) could profit from core functionality that outputs an integer number (or a floating-point number) with thousands separator.
Function format_float in lib/moodlelib.php allows for output of a floating-point value with a decimal separator. It never includes a separator between groups of thousands. The function can also be used to output integer numbers. And it allows for localised output.
I would like to suggest a change to format_float that adds a boolean parameter (like $usethousandsseparator) with a default value of false. If the value is false, the function behaves as it does now. If the parameter is true, a ',' (comma) is inserted between groups of thousands if $localized is false, and the value of string thousandssep is used instead to group thousands if $localized is true.
Possible edge cases to consider:
- decsep and thousandssep are the same value,
- one or both of decsep and thousandssep are empty,
- one or both of decsep and thousandssep are longer than one character (or byte),
- combinations of these cases.