I’m trying to work with jQuery’s slider plugin and it works great, only I need to format the output into a readable number, with commas such as 30,402,424 as opposed to 30402424.
I know it’s possible with javascript but the only ways I’ve found are very long winded. I’ve created a fiddle so you can see what I mean…
Javascript itself does not have support for formatting the numbers as you need, but with some googling I found the following familiar solution that I have used in the past, somewhat revised for better code quality.
Source: http://www.mredkj.com/javascript/numberFormat.html
Updated fiddle: http://jsfiddle.net/EX5U7/8/
Here’s another solution, which implements PHP’s
number_formatfunction in Javascript, allowing you to do even more than just blatantly add commas every 3 numbers:Usage:
number_format(123456.789, 2, '.', ',');results in123,456.79Source: http://phpjs.org/functions/number_format:481
Fiddle: http://jsfiddle.net/EX5U7/10/