Add point to every three numbers (thousand) in an input range tooltip?

Asked

Viewed 1,579 times

2

How do I add "mile point" to the numbers, R$1000 for R$1.000 in an input range tooltip:

inserir a descrição da imagem aqui

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);

  • 3

    Have you tried using the .toLocaleString as in this case http://answall.com/a/147086/129 ?

1 answer

2


Brow, I don’t know if there’s anything native that does that. 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;
}
  • Good worked out, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.