Well, if you have a number like 0.123456 , that is, the result of division, to give a percentage, multiply it by 100, and then round it or use toFixed , as in your example.
Math.round(0.123456 * 100)
Here is the jQuery plugin for this:
jQuery.extend({ percentage: function(a, b) { return Math.round((a / b) * 100); } });
Using:
alert($.percentage(6, 10));
Alex Turpin Dec 15 '11 at 15:46 2011-12-15 15:46
source share