I’m looking for having the functionality to display numbers with decimals using the Counter Element. There are a couple workarounds that I know of, but I’m hoping for a better way.
One way to get around it is to use the prefix to contain the whole number digits, and “count” up the digits past the decimal. But that’s obviously not ideal.
The other solution I found was using some Javascript code that alters the final counter value to include a comma every 3 digits. I modified this to do a decimal every 2 digits because I won’t have numbers higher than “99.99”. However, this is not ideal either because it uses a timeout value that waits for the count to finish, then tosses in the decimal. I’m wanting to use it on a page with about 18 counters, so I had to do this code 18 different times to make sure it all works properly. Page: http://okumf.org/okumf_v2/resources/investment-funds/.
Code sample:
jQuery(document).ready(function() { setTimeout(function() { var selector1 = jQuery('#dvf-ytd .number'); var theNumber1 = selector1.text(); theNumber1 = theNumber1.toString().replace(/\B(?=(\d{2})+(?!\d))/g, "."); selector1.text(theNumber1); }, 600); })
But this also has a problem when some of the counters are below the fold, and don’t start counting until you scroll, which means I can’t use the timeout function in the javascript properly.
ANYWAY, help?