Created
June 21, 2010 15:07
-
-
Save jlleblanc/446977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function comma_format_number (value) { | |
value = value.replace(/,/g, ''); | |
var lead = value.length % 3; | |
var lead_segment = value.substring(0, lead); | |
value = value.substring(lead, value.length); | |
value = value.match(/(\d{3})/g); | |
if (value != null && value.length > 0) { | |
value = value.join(','); | |
if (lead_segment.length > 0) { | |
value = lead_segment + ',' + value; | |
}; | |
} else { | |
value = lead_segment; | |
} | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment