Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: jQuery Number Counter with Sign

Zack:

How do count up from 0 to number with the sign? Numbers are coming from DB using a custom function to add K, M, B the using jquery counter up to show animation from 0 to lets say 1500, but actual display is 1.5K.

When I run counter() it removes K,M,B and 1.5K become 1.50. I am trying to get exact 1.5K but with counter style animation


function number_format_short( $n, $precision = 1 ) {
if ($n // 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n // 0.9k-850k
$n_format = number_format($n / 1000, $precision);
$suffix = 'K';
} else if ($n // 0.9m-850m
$n_format = number_format($n / 1000000, $precision);
$suffix = 'M';
} else if ($n // 0.9b-850b
$n_format = number_format($n / 1000000000, $precision);
$suffix = 'B';
} else {
// 0.9t+
$n_format = number_format($n / 1000000000000, $precision);
$suffix = 'T';
}
// Remove unecessary zeroes after decimal. "1.0" -> "1"; "1.00" -> "1"
// Intentionally does not affect partials, eg "1.50" -> "1.50"
if ( $precision > 0 ) {
$dotzero = '.' . str_repeat( '0', $precision );
$n_format = str_replace( $dotzero, '', $n_format );
}
return $n_format . $suffix;
}

function counter(){
$('.cnts').each(function (index) {
var size = $(this).text().split(".")[1] ? $(this).text().split(".")[1].length : 0;
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 1500,
easing: 'swing',
step: function (now) {
$(this).text(parseFloat(now).toFixed(size));
}
});
});
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: jQuery Number Counter with Sign

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×