I am using this jQuery script to display a counter. I need to show both whole numbers and decimals but I can't seem to determine which is which.
jQuery('.counter-wrap .count').each(function() {
jQuery(this).prop('Counter', 0).animate({
Counter: jQuery(this).attr('data-count')
}, {
duration: 1000,
easing: 'swing',
step: function(now) {
jQuery(this).text(
Math.round(this.Counter, 0) == this.Counter ?
this.Counter :
this.Counter.toFixed(1));
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="counter-wrap">
<h2><span class="count" data-count="6.8">0</span>M</h2>
</div>
<div class="counter-wrap">
<h2><span class="count" data-count="5.2">0</span>M</h2>
</div>
<div class="counter-wrap">
<h2><span class="count" data-count="90">0</span></h2>
</div>
Please check my fiddle