JavaScript – Format Numeric Values

This snippet put spaces between “number groups” to make the number more readable.

/**
 * Format numeric values.
 *
 * example: 12244556215 -> 12 244 556 215
 */
function format(value)
{
    return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}