INNER CODE UNIT · JavaScript
e
rweekly/rweekly.org · _includes/readable-number.js:1
var NumberStrings=function(){function e(e){this.options=e;var t={units:[{name:"hundred",value:100},{name:"thousand",value:1e3},{name:"million",value:1e6},{name:"billion",value:1e9},{name:"trillion",value:1e12},{name:"quadrillion",value:1e15},{name:"quintillion",value:1e18},{name:"sextillion",value:1e21},{name:"septillion",value:1e24}]};this.options=e||{};for(var n in t){if(t.hasOwnProperty(n)&&!this.options.hasOwnProperty(n)){this.options[n]=t[n]}}this.units=this.options.units}e.prototype.getUnit=function(e){var t=null;for(var n=0;n<this.units.length;n++){if(e<this.units[n].value){break}if(e>=this.units[n].value){t=this.units[n]}}return t};e.prototype.getName=function(e){var t=this.getUnit(e);if(t){return t.name}else{return null}};e.prototype.getDecimal=function(e){var t=this.getUnit(e);if(t){return parseFloat(e/t.value)}else{return e}};e.prototype.format=function(e){var t=this.getUnit(e);if(t){return this.getDecimal(e)+" "+this.getName(e)}else{return e}};return e}();if(typeof exports!=="undefined"&&this.exports!==exports){module.exports=NumberStrings};