JSFiddle - React, Tailwind, and code Playground
HTML
Test <div class="counter">92.1</div>
<div class="counter">92</div>
<div class="counter">92.14</div>
CSS
.counter,
.counter-two,
.counter-one{
font-size: 30px;
}
JavaScript
function startCounter(){
$('.counter').each(function (index) {
var size = $(this).text().split(".")[1] ? $(this).text().split(".")[1].length : 0;
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 2000,
easing: 'swing',
step: function (now) {
$(this).text(parseFloat(now).toFixed(size));
}
});
});
}
startCounter();