1

I'm using dragdealer.js and this is what I have got so far:

Fiddle

While dragging through the slide, it gives an output,

Question: 1) How can I add a "," (comma) to the output after hundreds unit while dragging?

-> Right now:-$ 4023
-> Required Output:- $ 4,023

2) How to implement step so that it shows output is in multiple of 100?

-> Required Output:- $ 4.100 (multiple of 100)

Here is my code:

JS:

$(function() {

  new Dragdealer('just-a-slider', {
    animationCallback: function(x, y) {
      $('#dragValue').text(Math.round(x * 15000));
    }
  });

  var availHeight = $('.content-body').outerHeight() -
                    $('.content-mask').outerHeight();
  new Dragdealer('content-scroller', {
    horizontal: false,
    vertical: true,
    yPrecision: availHeight,
    animationCallback: function(x, y) {
      $('.content-body').css('margin-top', -y * availHeight);
    }
  });
});
CodeMonk
  • 920
  • 1
  • 12
  • 22

3 Answers3

2

I believe this question has already been answered Here, but with commas.

Replace the "," with "." and it should work.

Community
  • 1
  • 1
Magikaas
  • 224
  • 2
  • 10
2

You can use .replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") to add in the comma, and if divide your base by 100, ( = 150 ), you will step through in 100's and can append additional 0's onto your text output as required.

See fiddle here : http://jsfiddle.net/535Pd/4/

presidentnickson
  • 1,075
  • 8
  • 17
0

Question: 1) How can I add a "," (comma) to the output after hundreds unit while dragging?

-> Right now:-$ 4023
-> Required Output:- $ 4,023

4023/1000

2) How to implement step so that it shows output is in multiple of 100?

-> Required Output:- $ 4.100 (multiple of 100)

var str = (4023/1000).toString().split('.');
str[1] = Math.floor(str[1]); //Looks like you want to round down. If not, use ceil() or round()
var out = parseFloat(str.join('.'));
Bill
  • 3,478
  • 23
  • 42