List of utility methods to do Number Calculate
frac()Number.prototype.frac = function() { return this - Math.floor(this); }; | |
fuzzyEqual(otherNumber)Number.prototype.fuzzyEqual = function(otherNumber) return Math.abs(this - otherNumber) <= 0.00001; | |
gcd(b)Number.prototype.gcd = function(b) { return (b == 0) ? this : this.gcd(this % b); | |
getDecimalgetDecimal()Number.prototype.getDecimal = function getDecimal() { return parseInt(this, 10); }; | |
getDisplayText(number)Number.getDisplayText = function(number) { if (number < 1000) { return number; if (number < 1000000) { return (number / 1000).toFixed(1) * 1 + "k"; return (number / 1000000).toFixed(1) * 1 + "m"; }; ... | |
getHashCode()Number.prototype.getHashCode = function () { var x = this; x = ((x >> 16) ^ x) * 0x45d9f3b; x = ((x >> 16) ^ x) * 0x45d9f3b; x = ((x >> 16) ^ x); return x; }; | |
getHisByMs()Number.prototype.getHisByMs=function(){ var ms=this; var date=new Date(ms); var his=[]; his.push(Number(date.getHours()).addZero()); his.push(Number(date.getMinutes()).addZero()); his.push(Number(date.getSeconds()).addZero()); return his; | |
getPrecisiongetPrecision(length)Number.prototype.getPrecision = function getPrecision(length) { var value = parseFloat(this); if (Number.isFloat(value)) { return value.toString().split(".")[1].length; return 0; }; | |
getValue(arguments)var BigNumber = function(n){ this.value = n.toString(); this.getValue = function(){ return this.value; this.getRealValue = function(){ return Number(this.value); this.add = function(bnum){ ... | |
greaterThan(num)Number.prototype.greaterThan = function(num) { return this > num; |