Rails-like number_with_delimiter in javascript

Number.prototype.number_with_delimiter = function(delimiter, separator) { var number = this + ''; separator = separator || '.'; delimiter = delimiter || ','; var split = number.split(separator); split[0] = split[0].replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + delimiter ); return split.join(separator); };
A display helper for numbers to include commas or periods similar to the Rails method found here:

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.