Add point to every three numbers (thousands) in a tooltip of the input range?

1

How do I add a "thousand point" in numbers, R$1000 to R$1.000 in a tooltip of the input range:

Code:

var mySlider = $("input#valores");

	$('#valores-credito, #valores-parcela').slider({
		formatter: function(value) {
			return 'R$ ' + value + '';
		}
	});

	var value = mySlider.slider('getValue');

			mySlider
					.slider('setValue', 0);
    
asked by anonymous 02.09.2016 / 22:15

1 answer

2

Brow, I do not know if there's anything native that does it. But I did this function there that solves:

...
$('#valores-credito, #valores-parcela').slider({
    formatter: function(value) {
        return 'R$ ' + milhar( value ) + '';
    }
});
...

function milhar(n){
    var n = ''+n, t = n.length -1, novo = '';

    for( var i = t, a = 1; i >=0; i--, a++ ){
        var ponto = a % 3 == 0 && i > 0 ? '.' : '';
        novo = ponto + n.charAt(i) + novo;
    }
    return novo;
}
    
03.09.2016 / 19:03