List of utility methods to do Number to Readable Format
toHumanSize(bytes)Number.toHumanSize = function(bytes) { var labels = ['Bytes', 'kB', 'MB', 'GB', 'TB']; if (bytes === 0) { return 'n/a'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + labels[i]; }; | |
toHumanTime(elapsed)Number.toHumanTime = function(elapsed) { var labels = ['ms', 's', 'm', 'h', 'd']; var sizes = [1000, 60, 60, 24]; var data = []; sizes.forEach(function(value) { data.push(elapsed % value); elapsed = parseInt(elapsed / value); }); var pos = 0; ... | |
humanReadableOrder()Number.prototype.humanReadableOrder = function() { if (this>=1000000000) { return (this/1000000000).toFixed(1)+'b'; if (this>=1000000) { return (this/1000000).toFixed(1)+'m'; if (this>=1000) { return (this/1000).toFixed(1)+'k'; ... | |
humanReadablePrice()Number.prototype.humanReadablePrice = function() { return (this/10000).toFixed(2); }; | |
toEnglish()var numbersToWords = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', ... | |
toEnglish()var numbersToWords = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', ... | |
to_kilometers()Number.prototype.to_kilometers = function() { return this / 1000.0; }; | |
to_kilometers_per_hour()Number.prototype.to_kilometers_per_hour = function() { return this / 1000.0 * 3600.0; }; | |
to_miles()Number.prototype.to_miles = function() { return this / 1609.344; }; | |
to_miles_per_hour()Number.prototype.to_miles_per_hour = function() { return this / 1609.344 * 3600.0; }; |