Maxim
Maxim

Reputation: 83

No UiSlider remove decimal?

How to remove decimals digit from linked output

I am using this code

$("#slider_01").noUiSlider({
    start: [2000, 24000],
    connect: true,
    step: 0.01,

    range: {
        'min': 0,
        'max': 28500
    },
    format: wNumb({
        decimals: false,
        thousand: ',',
        prefix: '$ ',
    })
});

$('#slider_01').Link('lower').to($('#value-lower_1'));

$('#slider_01').Link('upper').to($('#value-upper_1'));

Upvotes: 6

Views: 11599

Answers (4)

rahimv
rahimv

Reputation: 581

I know it's a very old question, but I did not want to include another library Wnumb just to remove the decimal from one place. Here is my solution without using the wnumb.

    var slider = document.getElementById('prcsldr');
    noUiSlider.create(slider, {
        start: [10000],
        range: {
            min: 1000,
            max: 50000              
        },
        step: 1000,
        format:{
            to: (v) => v | 0,
            from: (v) => v | 0
        }
    });

Upvotes: 3

Zze
Zze

Reputation: 18805

I didn't have access to the wNumb library in the environment I was working with.

Had a look under the hood in the library and this also works:

$("#slider_01").noUiSlider({
    ...
    format: {
        to: (v) => parseFloat(v).toFixed(0),
        from: (v) => parseFloat(v).toFixed(0)
    }
});

Upvotes: 10

Lg102
Lg102

Reputation: 4898

Decimals decimals: false is invalid, use decimals: 0. Also, you are setting formatting for the .val() method. Use it like this:

$('#slider_01').Link('lower').to($('#value-lower_1'), null, wNumb({
    decimals: 0,
    thousand: ',',
    prefix: '$ ',
}));

Upvotes: 4

Stobor
Stobor

Reputation: 45132

Change the step from 0.01 to 1.

Upvotes: 0

Related Questions