Here you can find the source of toPercent(ofTotalAmount)
Number.prototype.toPercent = function (ofTotalAmount) { "use strict"; var n, t;//from w w w .ja v a2 s . c om var sign, suffix, i; n = this; try { // assume base of 100 t = (typeof ofTotalAmount === 'undefined' || isNaN(ofTotalAmount)) ? 100 : ofTotalAmount; if (t === 0) throw "division exception averted"; if (t <= n) throw "is too low"; sign = (n < 0) ? '-' : ''; suffix = '%'; i = parseInt(n = Math.abs(n * t)) + ''; } catch (err) { console.log("Error: " + err + "."); } finally { return sign + i + suffix; } return sign + i + suffix; };
Number.prototype.toPercent = function(n) { n = n || 0; return (Math.round(this * Math.pow(10, n + 2)) / Math.pow(10, n)).toFixed(n) + '%';
Number.prototype.toPercent = function(places) { return (this * 100).toFixed(places) + '%'; };
Number.prototype.toPercentage = function (radix) { var num = this * 100; return num.roundToFixed(radix); };