0

I am using the jquery ui range slider. Trying to add comma to the numbers so it will bore readable. tried like yo different ways including regex and parseFloatbut without success.

this is the jsfiddle.

DavSev
  • 1,005
  • 4
  • 22
  • 47

2 Answers2

2

This is what you want ? https://jsfiddle.net/sxd60y6x/

NUMBER.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")

See : How to print a number with commas as thousands separators in JavaScript

Akim Benchiha
  • 150
  • 1
  • 12
2

You can use toLocaleString method.

Here is how your code should look like.

$("#slider-range").slider({
    range: true,
    min: 10000,
    max: 10000000,
    values: [1000000, 4000000],
    slide: function(event, ui) {
        var minVal = ui.values[0].toLocaleString();
        var maxVal = ui.values[1].toLocaleString();
        $("#amount").val("₪" + minVal + " - ₪" + maxVal);
    }
});

And you need to do the same to your initial value code.

$("#amount").val("₪" + $("#slider-range").slider("values", 0).toLocaleString() + " - ₪" + $("#slider-range").slider("values", 1).toLocaleString());
Oshi
  • 494
  • 6
  • 13
  • Thank you! I have bee breaking my head with this for a few hours... How do I add commas to the `slider.min` and `slider.max` initial values? t – DavSev Dec 21 '17 at 08:16
  • @DavSev you need to do the same to your initial value code. I have edited my post to include it. – Oshi Dec 21 '17 at 12:07