Here you can find the source of toAbbr(precision)
// number.js/*from ww w. j a v a 2 s.c om*/ // // extensions to the native number type // return an abbreviation according to order of magnitude // ex: 10000.toAbbr(); // > 10K Number.prototype.toAbbr = function(precision) { if(this < 1000) return Math.round(this); else { var mag = Math.floor(Math.log(this) / Math.LN10 / 3); return (this / Math.pow(1000, mag)).toPrecision(precision || 3) + " KMBTP"[mag]; } };
Number.prototype.toApproximateTime = function () { sec_numb = parseInt(this); var approximateHours = (sec_numb / 3600).toFixedDown(1); var hours = Math.floor(sec_numb / 3600); var minutes = Math.floor((sec_numb - (hours * 3600)) / 60); var seconds = sec_numb - (hours * 3600) - (minutes * 60); var time = ''; if( approximateHours >= 1 ) { time = approximateHours + ' hours'; ...
Number.prototype.toBytes = function () { if (this === 0) { return '0 bytes' } var i = parseInt(Math.floor(Math.log(this) / Math.log(1024))) var r = Math.round(this / Math.pow(1024, i) * 10) / 10 return [r, ['bytes', 'KB', 'MB', 'GB', 'TB'][i]].join(' ')
Number.prototype.toCents = function(){ return this * 100; };
Number.prototype.toChar = function() { return String.fromCharCode(this); };