JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css">
<div id="slider-range"></div>
<input id="amount" type="text" size="40" />
JavaScript
var slider = $("#slider-range").slider({
range: true,
min: 0,
max: 100,
step: 1,
values: [10, 80],
slide: function (event, ui) {
$("#amount").val("RM " + commafy(ui.values[0]) + " to RM " + commafy(ui.values[1]));
}
});
$("#amount").val("RM " + commafy($("#slider-range").slider("values", 0)) +
" to RM " + commafy($("#slider-range").slider("values", 1)));
function commafy(val) {
/* Total range 0 - 2,500,000 */
/* 70% from 25,000 to 200,000, what have left (2,325,000) share left (25,000) and right (2,300,000) */
/* So, final dividing */
var toPresent = 0;
if (val < 10) {
toPresent = (val / 10) * 25000;
} else if (val <= 80) {
toPresent = 25000 + (val - 10) / 70 * 175000;
} else {
toPresent = 200000 + (val - 80) / 20 * 2300000;
};
return String(toPresent).split("").reverse().join("")
.replace(/(.{3}\B)/g, "$1,")
.split("").reverse().join("");
}