INNER CODE UNIT · JavaScript

DecimalNumber

Yaro2709/New-Star · scripts/base/bcmath.js:41

function DecimalNumber(num,precision){if(typeof(precision)=='undefined'){precision=0;};if(typeof(num)=='undefined'){num='0';};this.getPi=function(precision){if(precision>37){alert('Note: this approximation is not accurate above 37 decimal places');};return bcdiv('2646693125139304345','842468587426513207',precision);};this.toString=function(){return this._result;};this.floor=function(precision){this._result=bcadd(this._result,'0',0);return this;};this.ceil=function(precision){if(this._result.substr(0,1)=='-'){this._result=bcround(bcadd(this._result,'-0.5',1),0);}else{this._result=bcround(bcadd(this._result,'0.5',1),0);};return this;};this.toFixed=function(precision){return bcround(this._result,precision);};this.valueOf=function(){return this._result;};this.abs=function(){if(this._result.substr(0,1)=='-'){this._result=this._result.substr(1,this._result.length-1);};return this;};this.toInt=function(){return parseInt(this.toFixed(0));};this.toFloat=function(){return parseFloat(this._result);};this.add=function(operand){this._result=bcround(bcadd(this._result,this._parseNumber(operand),this._precision+2),this._precision);return this;};this.sub=function(operand){return this.subtract(operand);};this.subtract=function(operand){this._result=bcround(bcsub(this._result,this._parseNumber(operand),this._precision+2),this._precision);return this;};this.mul=function(operand){return this.multiply(operand);};this.multiply=function(operand){this._result=bcround(bcmul(this._result,this._parseNumber(operand),this._precision+2),this._precision);return this;};this.div=function(operand){return this.divide(operand);};this.divide=function(operand){this._result=bcround(bcdiv(this._result,this._parseNumber(operand),this._precision+2),this._precision);return this;};this.round=function(precision){this._result=bcround(this._result,precision);return this;};this.setPrecision=function(precision){this._precision=precision;this.round(precision);return this;};this._parseNumber=function(num){var tmp,r;tmp=num.toString().replace(/[^0-9\-\.]/g,'');if(tmp===''){return'0';};return tmp;};this.reset=function(num){if(typeof(num)=='undefined'){num=0;};this._result=bcround(num,this._precision);return this;};this._precision=precision;this._result=bcround(this._parseNumber(num),this._precision);};function TestFloatingPointProblems(){var x=0;x+=0.1;x+=0.7;x=x*10;x=Math.floor(x).toString();if(x==='8'){alert

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…