js-big-decimal
Advanced tools
Comparing version 1.1.7 to 1.1.8
declare class bigDecimal { | ||
private value; | ||
private static validate(number); | ||
constructor(number?: string); | ||
constructor(number?: number | string); | ||
getValue(): string; | ||
static getPrettyValue(number: any, digits: any, separator: any): string; | ||
getPrettyValue(digits: any, separator: any): string; | ||
static round(number: any, precision: any): string; | ||
round(precision: any): bigDecimal; | ||
static round(number: any, precision?: number): string; | ||
round(precision?: number): bigDecimal; | ||
static floor(number: any): any; | ||
floor(): bigDecimal; | ||
static ceil(number: any): any; | ||
ceil(): bigDecimal; | ||
static add(number1: any, number2: any): string; | ||
@@ -11,0 +15,0 @@ add(number: bigDecimal): bigDecimal; |
@@ -197,4 +197,9 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
input = input.toString(); | ||
var neg = false; | ||
if (input[0] === '-') { | ||
neg = true; | ||
input = input.substring(1); | ||
} | ||
var parts = input.split('.'), partInt = parts[0], partDec = parts[1]; | ||
//handle case of -ve input | ||
//handle case of -ve n | ||
if (n < 0) { | ||
@@ -208,3 +213,3 @@ n = -n; | ||
prefix = roundOff(input); | ||
return prefix + (new Array(n + 1).join('0')); | ||
return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0')); | ||
} | ||
@@ -215,11 +220,11 @@ } | ||
if (greaterThanFive(parts[1], partInt)) { | ||
return increment(partInt); | ||
return (neg ? '-' : '') + increment(partInt); | ||
} | ||
return partInt; | ||
return (neg ? '-' : '') + partInt; | ||
} | ||
if (!parts[1]) { | ||
return partInt + '.' + (new Array(n + 1).join('0')); | ||
return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0')); | ||
} | ||
else if (parts[1].length < n) { | ||
return partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0')); | ||
return (neg ? '-' : '') + partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0')); | ||
} | ||
@@ -234,3 +239,3 @@ partDec = parts[1].substring(0, n); | ||
} | ||
return partInt + '.' + partDec; | ||
return (neg ? '-' : '') + partInt + '.' + partDec; | ||
} | ||
@@ -347,6 +352,5 @@ exports.roundOff = roundOff; | ||
bigDecimal.round = function (number, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
number = bigDecimal.validate(number); | ||
if (!precision) | ||
precision = 0; | ||
else if (isNaN(precision)) | ||
if (isNaN(precision)) | ||
throw Error("Precision is not a number: " + precision); | ||
@@ -356,8 +360,29 @@ return round_1.roundOff(number, precision); | ||
bigDecimal.prototype.round = function (precision) { | ||
if (!precision) | ||
precision = 0; | ||
else if (isNaN(precision)) | ||
if (precision === void 0) { precision = 0; } | ||
if (isNaN(precision)) | ||
throw Error("Precision is not a number: " + precision); | ||
return new bigDecimal(round_1.roundOff(this.value, precision)); | ||
}; | ||
bigDecimal.floor = function (number) { | ||
number = bigDecimal.validate(number); | ||
if (number.indexOf('.') === -1) | ||
return number; | ||
return bigDecimal.round(bigDecimal.subtract(number, 0.5)); | ||
}; | ||
bigDecimal.prototype.floor = function () { | ||
if (this.value.indexOf('.') === -1) | ||
return new bigDecimal(this.value); | ||
return this.subtract(new bigDecimal(0.5)).round(); | ||
}; | ||
bigDecimal.ceil = function (number) { | ||
number = bigDecimal.validate(number); | ||
if (number.indexOf('.') === -1) | ||
return number; | ||
return bigDecimal.round(bigDecimal.add(number, 0.5)); | ||
}; | ||
bigDecimal.prototype.ceil = function () { | ||
if (this.value.indexOf('.') === -1) | ||
return new bigDecimal(this.value); | ||
return this.add(new bigDecimal(0.5)).round(); | ||
}; | ||
bigDecimal.add = function (number1, number2) { | ||
@@ -364,0 +389,0 @@ number1 = bigDecimal.validate(number1); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.bigDecimal=e():t.bigDecimal=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function n(t,e){void 0===e&&(e="0");var r=0,n=-1;"-"==t[0]&&(r++,n=1,t=t.substring(1),t.length),"-"==e[0]&&(r++,n=2,e=e.substring(1),e.length),t=u(t),e=u(e),l=o(u(t),u(e)),t=l[0],e=l[1],1==r&&(1==n?t=i(t):e=i(e));var s=a(t,e);return r?2==r?"-"+u(s):t.length<s.length?u(s.substring(1)):"-"+u(i(s)):u(s);var l}function i(t){for(var e="",r=t.length,n=t.split(".")[1],i=n?n.length:0,u=0;u<r;u++)t[u]>="0"&&t[u]<="9"?e+=9-parseInt(t[u]):e+=t[u];return a(e,i>0?"0."+new Array(i).join("0")+"1":"1")}function u(t){var e=t.split(".");for(e[0]||(e[0]="0");"0"==e[0][0]&&e[0].length>1;)e[0]=e[0].substring(1);return e[0]+(e[1]?"."+e[1]:"")}function o(t,e){var r=t.split("."),n=e.split("."),i=r[0].length,u=n[0].length;return i>u?n[0]=new Array(Math.abs(i-u)+1).join("0")+(n[0]?n[0]:""):r[0]=new Array(Math.abs(i-u)+1).join("0")+(r[0]?r[0]:""),i=r[1]?r[1].length:0,u=n[1]?n[1].length:0,(i||u)&&(i>u?n[1]=(n[1]?n[1]:"")+new Array(Math.abs(i-u)+1).join("0"):r[1]=(r[1]?r[1]:"")+new Array(Math.abs(i-u)+1).join("0")),t=r[0]+(r[1]?"."+r[1]:""),e=n[0]+(n[1]?"."+n[1]:""),[t,e]}function a(t,e){a=o(t,e),t=a[0],e=a[1];for(var r="",n=0,i=t.length-1;i>=0;i--)if("."!==t[i]){var u=parseInt(t[i])+parseInt(e[i])+n;r=u%10+r,n=Math.floor(u/10)}else r="."+r;return n?n.toString()+r:r;var a}Object.defineProperty(e,"__esModule",{value:!0}),e.add=n,e.trim=u,e.pad=o},function(t,e,r){"use strict";function n(t,e){void 0===e&&(e=0),"number"==typeof t&&(t=t.toString());var r=t.split("."),o=r[0],a=r[1];if(e<0){if(e=-e,o.length<=e)return"0";var s=o.substr(0,o.length-e);return t=s+"."+o.substr(o.length-e)+a,(s=n(t))+new Array(e+1).join("0")}if(0==e){o.length;return i(r[1],o)?u(o):o}if(!r[1])return o+"."+new Array(e+1).join("0");if(r[1].length<e)return o+"."+r[1]+new Array(e-r[1].length+1).join("0");a=r[1].substring(0,e);var l=r[1].substring(e);return l&&i(l,a)&&(a=u(a),a.length>e)?u(o,parseInt(a[0]))+"."+a.substring(1):o+"."+a}function i(t,e){return!!t&&(t>"5"+new Array(t.length+1).join("0")||"5"==t&&parseInt(e[e.length-1])%2==1)}function u(t,e){void 0===e&&(e=0),e||(e=1),"number"==typeof t&&t.toString();for(var r=t.length-1,n="",i=r;i>=0;i--){var u=parseInt(t[i])+e;10==u?(e=1,u=0):e=0,n+=u}return e&&(n+=e),n.split("").reverse().join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.roundOff=n},function(t,e,r){"use strict";var n=r(0),i=r(1),u=r(3),o=r(4),a=r(5),s=r(6),l=function(){function t(e){void 0===e&&(e="0"),this.value=t.validate(e)}return t.validate=function(t){if(t){if(t=t.toString(),isNaN(t))throw Error("Parameter is not a number: "+t);"+"==t[0]&&(t=t.substring(1))}else t="0";if(/e/i.test(t)){var e=t.split(/[eE]/),r=e[0],i=e[1];r=n.trim(r),i=parseInt(i)+r.indexOf("."),r=r.replace(".",""),t=r.length<i?r+new Array(i-r.length+1).join("0"):r.length>=i&&i>0?n.trim(r.substring(0,i))+(r.length>i?"."+r.substring(i):""):"0."+new Array(1-i).join("0")+r}return t},t.prototype.getValue=function(){return this.value},t.getPrettyValue=function(e,r,n){if(r||n){if(!r||!n)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else r=3,n=",";e=t.validate(e);var i="-"==e.charAt(0);i&&(e=e.substring(1));var u=e.indexOf(".");u=u>0?u:e.length;for(var o="",a=u;a>0;)a<r?(r=a,a=0):a-=r,o=e.substring(a,a+r)+(a<u-r&&a>=0?n:"")+o;return(i?"-":"")+o+e.substring(u)},t.prototype.getPrettyValue=function(e,r){return t.getPrettyValue(this.value,e,r)},t.round=function(e,r){if(e=t.validate(e),r){if(isNaN(r))throw Error("Precision is not a number: "+r)}else r=0;return i.roundOff(e,r)},t.prototype.round=function(e){if(e){if(isNaN(e))throw Error("Precision is not a number: "+e)}else e=0;return new t(i.roundOff(this.value,e))},t.add=function(e,r){return e=t.validate(e),r=t.validate(r),n.add(e,r)},t.prototype.add=function(e){return new t(n.add(this.value,e.getValue()))},t.subtract=function(e,r){return e=t.validate(e),r=t.validate(r),s.subtract(e,r)},t.prototype.subtract=function(e){return new t(s.subtract(this.value,e.getValue()))},t.multiply=function(e,r){return e=t.validate(e),r=t.validate(r),u.multiply(e,r)},t.prototype.multiply=function(e){return new t(u.multiply(this.value,e.getValue()))},t.divide=function(e,r,n){return e=t.validate(e),r=t.validate(r),o.divide(e,r,n)},t.prototype.divide=function(e,r){return new t(o.divide(this.value,e.getValue(),r))},t.compareTo=function(e,r){return e=t.validate(e),r=t.validate(r),a.compareTo(e,r)},t.prototype.compareTo=function(t){return a.compareTo(this.value,t.getValue())},t.negate=function(e){return e=t.validate(e),s.negate(e)},t.prototype.negate=function(){return new t(s.negate(this.value))},t}();t.exports=l},function(t,e,r){"use strict";function n(t,e){t=t.toString(),e=e.toString();var r=0;"-"==t[0]&&(r++,t=t.substr(1)),"-"==e[0]&&(r++,e=e.substr(1)),t=u(t),e=u(e);var n=0,o=0;-1!=t.indexOf(".")&&(n=t.length-t.indexOf(".")-1),-1!=e.indexOf(".")&&(o=e.length-e.indexOf(".")-1);var a=n+o;if(t=u(t.replace(".","")),e=u(e.replace(".","")),t.length<e.length){var s=t;t=e,e=s}if("0"==e)return"0";for(var l=e.length,f=0,g=[],c=l-1,d="",p=0;p<l;p++)g[p]=t.length-1;for(var p=0;p<2*t.length;p++){for(var v=0,h=e.length-1;h>=c&&h>=0;h--)g[h]>-1&&g[h]<t.length&&(v+=parseInt(t[g[h]--])*parseInt(e[h]));v+=f,f=Math.floor(v/10),d=v%10+d,c--}return d=u(i(d,a)),1==r&&(d="-"+d),d}function i(t,e){return 0==e?t:(t=e>=t.length?new Array(e-t.length+1).join("0")+t:t,t.substr(0,t.length-e)+"."+t.substr(t.length-e,e))}function u(t){for(;"0"==t[0];)t=t.substr(1);if(-1!=t.indexOf("."))for(;"0"==t[t.length-1];)t=t.substr(0,t.length-1);return""==t||"."==t?t="0":"."==t[t.length-1]&&(t=t.substr(0,t.length-1)),"."==t[0]&&(t="0"+t),t}Object.defineProperty(e,"__esModule",{value:!0}),e.multiply=n},function(t,e,r){"use strict";function n(t,e,r){if(void 0===r&&(r=8),0==e)throw new Error("Cannot divide by 0");if(t=t.toString(),e=e.toString(),0==t)return"0";var n=0;"-"==e[0]&&(e=e.substring(1),n++),"-"==t[0]&&(t=t.substring(1),n++);var o=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(e=i.trim(e.replace(".","")),o>=0){var a=t.indexOf(".")>0?t.length-t.indexOf(".")-1:-1;if(-1==a)t=i.trim(t+new Array(o+1).join("0"));else if(o>a)t=t.replace(".",""),t=i.trim(t+new Array(o-a+1).join("0"));else if(o<a){t=t.replace(".","");var s=t.length-o+o;t=i.trim(t.substring(0,s)+"."+t.substring(s))}else o==a&&(t=i.trim(t.replace(".","")))}var l=0,f=e.length,g="",c=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(0,f+1):t.substring(0,f);if(t=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(f+1):t.substring(f),c.indexOf(".")>-1){var d=c.length-c.indexOf(".")-1;c=c.replace(".",""),f>c.length&&(d+=f-c.length,c+=new Array(f-c.length+1).join("0")),l=d,g="0."+new Array(d).join("0")}for(r+=2;l<=r;){for(var p=0;parseInt(c)>=parseInt(e);)c=i.add(c,"-"+e),p++;g+=p,t?("."==t[0]&&(g+=".",l++,t=t.substring(1)),c+=t.substring(0,1),t=t.substring(1)):(l||(g+="."),l++,c+="0")}return(1==n?"-":"")+i.trim(u.roundOff(g,r-2))}Object.defineProperty(e,"__esModule",{value:!0});var i=r(0),u=r(1);e.divide=n},function(t,e,r){"use strict";function n(t,e){var r=!1;if("-"==t[0]&&"-"!=e[0])return-1;if("-"!=t[0]&&"-"==e[0])return 1;if("-"==t[0]&&"-"==e[0]&&(t=t.substr(1),e=e.substr(1),r=!0),u=i.pad(t,e),t=u[0],e=u[1],0==t.localeCompare(e))return 0;for(var n=0;n<t.length;n++)if(t[n]!=e[n])return t[n]>e[n]?r?-1:1:r?1:-1;return 0;var u}Object.defineProperty(e,"__esModule",{value:!0});var i=r(0);e.compareTo=n},function(t,e,r){"use strict";function n(t,e){return t=t.toString(),e=e.toString(),e=i(e),u.add(t,e)}function i(t){return t="-"==t[0]?t.substr(1):"-"+t}Object.defineProperty(e,"__esModule",{value:!0});var u=r(0);e.subtract=n,e.negate=i}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.bigDecimal=e():t.bigDecimal=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function n(t,e){void 0===e&&(e="0");var r=0,n=-1;"-"==t[0]&&(r++,n=1,t=t.substring(1),t.length),"-"==e[0]&&(r++,n=2,e=e.substring(1),e.length),t=u(t),e=u(e),l=o(u(t),u(e)),t=l[0],e=l[1],1==r&&(1==n?t=i(t):e=i(e));var s=a(t,e);return r?2==r?"-"+u(s):t.length<s.length?u(s.substring(1)):"-"+u(i(s)):u(s);var l}function i(t){for(var e="",r=t.length,n=t.split(".")[1],i=n?n.length:0,u=0;u<r;u++)t[u]>="0"&&t[u]<="9"?e+=9-parseInt(t[u]):e+=t[u];return a(e,i>0?"0."+new Array(i).join("0")+"1":"1")}function u(t){var e=t.split(".");for(e[0]||(e[0]="0");"0"==e[0][0]&&e[0].length>1;)e[0]=e[0].substring(1);return e[0]+(e[1]?"."+e[1]:"")}function o(t,e){var r=t.split("."),n=e.split("."),i=r[0].length,u=n[0].length;return i>u?n[0]=new Array(Math.abs(i-u)+1).join("0")+(n[0]?n[0]:""):r[0]=new Array(Math.abs(i-u)+1).join("0")+(r[0]?r[0]:""),i=r[1]?r[1].length:0,u=n[1]?n[1].length:0,(i||u)&&(i>u?n[1]=(n[1]?n[1]:"")+new Array(Math.abs(i-u)+1).join("0"):r[1]=(r[1]?r[1]:"")+new Array(Math.abs(i-u)+1).join("0")),t=r[0]+(r[1]?"."+r[1]:""),e=n[0]+(n[1]?"."+n[1]:""),[t,e]}function a(t,e){a=o(t,e),t=a[0],e=a[1];for(var r="",n=0,i=t.length-1;i>=0;i--)if("."!==t[i]){var u=parseInt(t[i])+parseInt(e[i])+n;r=u%10+r,n=Math.floor(u/10)}else r="."+r;return n?n.toString()+r:r;var a}Object.defineProperty(e,"__esModule",{value:!0}),e.add=n,e.trim=u,e.pad=o},function(t,e,r){"use strict";function n(t,e){void 0===e&&(e=0),"number"==typeof t&&(t=t.toString());var r=!1;"-"===t[0]&&(r=!0,t=t.substring(1));var o=t.split("."),a=o[0],s=o[1];if(e<0){if(e=-e,a.length<=e)return"0";var l=a.substr(0,a.length-e);return t=l+"."+a.substr(a.length-e)+s,l=n(t),(r?"-":"")+l+new Array(e+1).join("0")}if(0==e){a.length;return i(o[1],a)?(r?"-":"")+u(a):(r?"-":"")+a}if(!o[1])return(r?"-":"")+a+"."+new Array(e+1).join("0");if(o[1].length<e)return(r?"-":"")+a+"."+o[1]+new Array(e-o[1].length+1).join("0");s=o[1].substring(0,e);var f=o[1].substring(e);return f&&i(f,s)&&(s=u(s),s.length>e)?u(a,parseInt(s[0]))+"."+s.substring(1):(r?"-":"")+a+"."+s}function i(t,e){return!!t&&(t>"5"+new Array(t.length+1).join("0")||"5"==t&&parseInt(e[e.length-1])%2==1)}function u(t,e){void 0===e&&(e=0),e||(e=1),"number"==typeof t&&t.toString();for(var r=t.length-1,n="",i=r;i>=0;i--){var u=parseInt(t[i])+e;10==u?(e=1,u=0):e=0,n+=u}return e&&(n+=e),n.split("").reverse().join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.roundOff=n},function(t,e,r){"use strict";var n=r(0),i=r(1),u=r(3),o=r(4),a=r(5),s=r(6),l=function(){function t(e){void 0===e&&(e="0"),this.value=t.validate(e)}return t.validate=function(t){if(t){if(t=t.toString(),isNaN(t))throw Error("Parameter is not a number: "+t);"+"==t[0]&&(t=t.substring(1))}else t="0";if(/e/i.test(t)){var e=t.split(/[eE]/),r=e[0],i=e[1];r=n.trim(r),i=parseInt(i)+r.indexOf("."),r=r.replace(".",""),t=r.length<i?r+new Array(i-r.length+1).join("0"):r.length>=i&&i>0?n.trim(r.substring(0,i))+(r.length>i?"."+r.substring(i):""):"0."+new Array(1-i).join("0")+r}return t},t.prototype.getValue=function(){return this.value},t.getPrettyValue=function(e,r,n){if(r||n){if(!r||!n)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else r=3,n=",";e=t.validate(e);var i="-"==e.charAt(0);i&&(e=e.substring(1));var u=e.indexOf(".");u=u>0?u:e.length;for(var o="",a=u;a>0;)a<r?(r=a,a=0):a-=r,o=e.substring(a,a+r)+(a<u-r&&a>=0?n:"")+o;return(i?"-":"")+o+e.substring(u)},t.prototype.getPrettyValue=function(e,r){return t.getPrettyValue(this.value,e,r)},t.round=function(e,r){if(void 0===r&&(r=0),e=t.validate(e),isNaN(r))throw Error("Precision is not a number: "+r);return i.roundOff(e,r)},t.prototype.round=function(e){if(void 0===e&&(e=0),isNaN(e))throw Error("Precision is not a number: "+e);return new t(i.roundOff(this.value,e))},t.floor=function(e){return e=t.validate(e),-1===e.indexOf(".")?e:t.round(t.subtract(e,.5))},t.prototype.floor=function(){return-1===this.value.indexOf(".")?new t(this.value):this.subtract(new t(.5)).round()},t.ceil=function(e){return e=t.validate(e),-1===e.indexOf(".")?e:t.round(t.add(e,.5))},t.prototype.ceil=function(){return-1===this.value.indexOf(".")?new t(this.value):this.add(new t(.5)).round()},t.add=function(e,r){return e=t.validate(e),r=t.validate(r),n.add(e,r)},t.prototype.add=function(e){return new t(n.add(this.value,e.getValue()))},t.subtract=function(e,r){return e=t.validate(e),r=t.validate(r),s.subtract(e,r)},t.prototype.subtract=function(e){return new t(s.subtract(this.value,e.getValue()))},t.multiply=function(e,r){return e=t.validate(e),r=t.validate(r),u.multiply(e,r)},t.prototype.multiply=function(e){return new t(u.multiply(this.value,e.getValue()))},t.divide=function(e,r,n){return e=t.validate(e),r=t.validate(r),o.divide(e,r,n)},t.prototype.divide=function(e,r){return new t(o.divide(this.value,e.getValue(),r))},t.compareTo=function(e,r){return e=t.validate(e),r=t.validate(r),a.compareTo(e,r)},t.prototype.compareTo=function(t){return a.compareTo(this.value,t.getValue())},t.negate=function(e){return e=t.validate(e),s.negate(e)},t.prototype.negate=function(){return new t(s.negate(this.value))},t}();t.exports=l},function(t,e,r){"use strict";function n(t,e){t=t.toString(),e=e.toString();var r=0;"-"==t[0]&&(r++,t=t.substr(1)),"-"==e[0]&&(r++,e=e.substr(1)),t=u(t),e=u(e);var n=0,o=0;-1!=t.indexOf(".")&&(n=t.length-t.indexOf(".")-1),-1!=e.indexOf(".")&&(o=e.length-e.indexOf(".")-1);var a=n+o;if(t=u(t.replace(".","")),e=u(e.replace(".","")),t.length<e.length){var s=t;t=e,e=s}if("0"==e)return"0";for(var l=e.length,f=0,d=[],g=l-1,c="",v=0;v<l;v++)d[v]=t.length-1;for(var v=0;v<2*t.length;v++){for(var p=0,h=e.length-1;h>=g&&h>=0;h--)d[h]>-1&&d[h]<t.length&&(p+=parseInt(t[d[h]--])*parseInt(e[h]));p+=f,f=Math.floor(p/10),c=p%10+c,g--}return c=u(i(c,a)),1==r&&(c="-"+c),c}function i(t,e){return 0==e?t:(t=e>=t.length?new Array(e-t.length+1).join("0")+t:t,t.substr(0,t.length-e)+"."+t.substr(t.length-e,e))}function u(t){for(;"0"==t[0];)t=t.substr(1);if(-1!=t.indexOf("."))for(;"0"==t[t.length-1];)t=t.substr(0,t.length-1);return""==t||"."==t?t="0":"."==t[t.length-1]&&(t=t.substr(0,t.length-1)),"."==t[0]&&(t="0"+t),t}Object.defineProperty(e,"__esModule",{value:!0}),e.multiply=n},function(t,e,r){"use strict";function n(t,e,r){if(void 0===r&&(r=8),0==e)throw new Error("Cannot divide by 0");if(t=t.toString(),e=e.toString(),0==t)return"0";var n=0;"-"==e[0]&&(e=e.substring(1),n++),"-"==t[0]&&(t=t.substring(1),n++);var o=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(e=i.trim(e.replace(".","")),o>=0){var a=t.indexOf(".")>0?t.length-t.indexOf(".")-1:-1;if(-1==a)t=i.trim(t+new Array(o+1).join("0"));else if(o>a)t=t.replace(".",""),t=i.trim(t+new Array(o-a+1).join("0"));else if(o<a){t=t.replace(".","");var s=t.length-o+o;t=i.trim(t.substring(0,s)+"."+t.substring(s))}else o==a&&(t=i.trim(t.replace(".","")))}var l=0,f=e.length,d="",g=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(0,f+1):t.substring(0,f);if(t=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(f+1):t.substring(f),g.indexOf(".")>-1){var c=g.length-g.indexOf(".")-1;g=g.replace(".",""),f>g.length&&(c+=f-g.length,g+=new Array(f-g.length+1).join("0")),l=c,d="0."+new Array(c).join("0")}for(r+=2;l<=r;){for(var v=0;parseInt(g)>=parseInt(e);)g=i.add(g,"-"+e),v++;d+=v,t?("."==t[0]&&(d+=".",l++,t=t.substring(1)),g+=t.substring(0,1),t=t.substring(1)):(l||(d+="."),l++,g+="0")}return(1==n?"-":"")+i.trim(u.roundOff(d,r-2))}Object.defineProperty(e,"__esModule",{value:!0});var i=r(0),u=r(1);e.divide=n},function(t,e,r){"use strict";function n(t,e){var r=!1;if("-"==t[0]&&"-"!=e[0])return-1;if("-"!=t[0]&&"-"==e[0])return 1;if("-"==t[0]&&"-"==e[0]&&(t=t.substr(1),e=e.substr(1),r=!0),u=i.pad(t,e),t=u[0],e=u[1],0==t.localeCompare(e))return 0;for(var n=0;n<t.length;n++)if(t[n]!=e[n])return t[n]>e[n]?r?-1:1:r?1:-1;return 0;var u}Object.defineProperty(e,"__esModule",{value:!0});var i=r(0);e.compareTo=n},function(t,e,r){"use strict";function n(t,e){return t=t.toString(),e=e.toString(),e=i(e),u.add(t,e)}function i(t){return t="-"==t[0]?t.substr(1):"-"+t}Object.defineProperty(e,"__esModule",{value:!0});var u=r(0);e.subtract=n,e.negate=i}])}); |
@@ -188,4 +188,9 @@ var bigDecimal = | ||
input = input.toString(); | ||
var neg = false; | ||
if (input[0] === '-') { | ||
neg = true; | ||
input = input.substring(1); | ||
} | ||
var parts = input.split('.'), partInt = parts[0], partDec = parts[1]; | ||
//handle case of -ve input | ||
//handle case of -ve n | ||
if (n < 0) { | ||
@@ -199,3 +204,3 @@ n = -n; | ||
prefix = roundOff(input); | ||
return prefix + (new Array(n + 1).join('0')); | ||
return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0')); | ||
} | ||
@@ -206,11 +211,11 @@ } | ||
if (greaterThanFive(parts[1], partInt)) { | ||
return increment(partInt); | ||
return (neg ? '-' : '') + increment(partInt); | ||
} | ||
return partInt; | ||
return (neg ? '-' : '') + partInt; | ||
} | ||
if (!parts[1]) { | ||
return partInt + '.' + (new Array(n + 1).join('0')); | ||
return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0')); | ||
} | ||
else if (parts[1].length < n) { | ||
return partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0')); | ||
return (neg ? '-' : '') + partInt + '.' + parts[1] + (new Array(n - parts[1].length + 1).join('0')); | ||
} | ||
@@ -225,3 +230,3 @@ partDec = parts[1].substring(0, n); | ||
} | ||
return partInt + '.' + partDec; | ||
return (neg ? '-' : '') + partInt + '.' + partDec; | ||
} | ||
@@ -338,6 +343,5 @@ exports.roundOff = roundOff; | ||
bigDecimal.round = function (number, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
number = bigDecimal.validate(number); | ||
if (!precision) | ||
precision = 0; | ||
else if (isNaN(precision)) | ||
if (isNaN(precision)) | ||
throw Error("Precision is not a number: " + precision); | ||
@@ -347,8 +351,29 @@ return round_1.roundOff(number, precision); | ||
bigDecimal.prototype.round = function (precision) { | ||
if (!precision) | ||
precision = 0; | ||
else if (isNaN(precision)) | ||
if (precision === void 0) { precision = 0; } | ||
if (isNaN(precision)) | ||
throw Error("Precision is not a number: " + precision); | ||
return new bigDecimal(round_1.roundOff(this.value, precision)); | ||
}; | ||
bigDecimal.floor = function (number) { | ||
number = bigDecimal.validate(number); | ||
if (number.indexOf('.') === -1) | ||
return number; | ||
return bigDecimal.round(bigDecimal.subtract(number, 0.5)); | ||
}; | ||
bigDecimal.prototype.floor = function () { | ||
if (this.value.indexOf('.') === -1) | ||
return new bigDecimal(this.value); | ||
return this.subtract(new bigDecimal(0.5)).round(); | ||
}; | ||
bigDecimal.ceil = function (number) { | ||
number = bigDecimal.validate(number); | ||
if (number.indexOf('.') === -1) | ||
return number; | ||
return bigDecimal.round(bigDecimal.add(number, 0.5)); | ||
}; | ||
bigDecimal.prototype.ceil = function () { | ||
if (this.value.indexOf('.') === -1) | ||
return new bigDecimal(this.value); | ||
return this.add(new bigDecimal(0.5)).round(); | ||
}; | ||
bigDecimal.add = function (number1, number2) { | ||
@@ -355,0 +380,0 @@ number1 = bigDecimal.validate(number1); |
@@ -1,1 +0,1 @@ | ||
var bigDecimal=function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}var e={};return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,e){"use strict";function n(t,r){void 0===r&&(r="0");var e=0,n=-1;"-"==t[0]&&(e++,n=1,t=t.substring(1),t.length),"-"==r[0]&&(e++,n=2,r=r.substring(1),r.length),t=u(t),r=u(r),l=a(u(t),u(r)),t=l[0],r=l[1],1==e&&(1==n?t=i(t):r=i(r));var s=o(t,r);return e?2==e?"-"+u(s):t.length<s.length?u(s.substring(1)):"-"+u(i(s)):u(s);var l}function i(t){for(var r="",e=t.length,n=t.split(".")[1],i=n?n.length:0,u=0;u<e;u++)t[u]>="0"&&t[u]<="9"?r+=9-parseInt(t[u]):r+=t[u];return o(r,i>0?"0."+new Array(i).join("0")+"1":"1")}function u(t){var r=t.split(".");for(r[0]||(r[0]="0");"0"==r[0][0]&&r[0].length>1;)r[0]=r[0].substring(1);return r[0]+(r[1]?"."+r[1]:"")}function a(t,r){var e=t.split("."),n=r.split("."),i=e[0].length,u=n[0].length;return i>u?n[0]=new Array(Math.abs(i-u)+1).join("0")+(n[0]?n[0]:""):e[0]=new Array(Math.abs(i-u)+1).join("0")+(e[0]?e[0]:""),i=e[1]?e[1].length:0,u=n[1]?n[1].length:0,(i||u)&&(i>u?n[1]=(n[1]?n[1]:"")+new Array(Math.abs(i-u)+1).join("0"):e[1]=(e[1]?e[1]:"")+new Array(Math.abs(i-u)+1).join("0")),t=e[0]+(e[1]?"."+e[1]:""),r=n[0]+(n[1]?"."+n[1]:""),[t,r]}function o(t,r){o=a(t,r),t=o[0],r=o[1];for(var e="",n=0,i=t.length-1;i>=0;i--)if("."!==t[i]){var u=parseInt(t[i])+parseInt(r[i])+n;e=u%10+e,n=Math.floor(u/10)}else e="."+e;return n?n.toString()+e:e;var o}Object.defineProperty(r,"__esModule",{value:!0}),r.add=n,r.trim=u,r.pad=a},function(t,r,e){"use strict";function n(t,r){void 0===r&&(r=0),"number"==typeof t&&(t=t.toString());var e=t.split("."),a=e[0],o=e[1];if(r<0){if(r=-r,a.length<=r)return"0";var s=a.substr(0,a.length-r);return t=s+"."+a.substr(a.length-r)+o,(s=n(t))+new Array(r+1).join("0")}if(0==r){a.length;return i(e[1],a)?u(a):a}if(!e[1])return a+"."+new Array(r+1).join("0");if(e[1].length<r)return a+"."+e[1]+new Array(r-e[1].length+1).join("0");o=e[1].substring(0,r);var l=e[1].substring(r);return l&&i(l,o)&&(o=u(o),o.length>r)?u(a,parseInt(o[0]))+"."+o.substring(1):a+"."+o}function i(t,r){return!!t&&(t>"5"+new Array(t.length+1).join("0")||"5"==t&&parseInt(r[r.length-1])%2==1)}function u(t,r){void 0===r&&(r=0),r||(r=1),"number"==typeof t&&t.toString();for(var e=t.length-1,n="",i=e;i>=0;i--){var u=parseInt(t[i])+r;10==u?(r=1,u=0):r=0,n+=u}return r&&(n+=r),n.split("").reverse().join("")}Object.defineProperty(r,"__esModule",{value:!0}),r.roundOff=n},function(t,r,e){"use strict";var n=e(0),i=e(1),u=e(3),a=e(4),o=e(5),s=e(6),l=function(){function t(r){void 0===r&&(r="0"),this.value=t.validate(r)}return t.validate=function(t){if(t){if(t=t.toString(),isNaN(t))throw Error("Parameter is not a number: "+t);"+"==t[0]&&(t=t.substring(1))}else t="0";if(/e/i.test(t)){var r=t.split(/[eE]/),e=r[0],i=r[1];e=n.trim(e),i=parseInt(i)+e.indexOf("."),e=e.replace(".",""),t=e.length<i?e+new Array(i-e.length+1).join("0"):e.length>=i&&i>0?n.trim(e.substring(0,i))+(e.length>i?"."+e.substring(i):""):"0."+new Array(1-i).join("0")+e}return t},t.prototype.getValue=function(){return this.value},t.getPrettyValue=function(r,e,n){if(e||n){if(!e||!n)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else e=3,n=",";r=t.validate(r);var i="-"==r.charAt(0);i&&(r=r.substring(1));var u=r.indexOf(".");u=u>0?u:r.length;for(var a="",o=u;o>0;)o<e?(e=o,o=0):o-=e,a=r.substring(o,o+e)+(o<u-e&&o>=0?n:"")+a;return(i?"-":"")+a+r.substring(u)},t.prototype.getPrettyValue=function(r,e){return t.getPrettyValue(this.value,r,e)},t.round=function(r,e){if(r=t.validate(r),e){if(isNaN(e))throw Error("Precision is not a number: "+e)}else e=0;return i.roundOff(r,e)},t.prototype.round=function(r){if(r){if(isNaN(r))throw Error("Precision is not a number: "+r)}else r=0;return new t(i.roundOff(this.value,r))},t.add=function(r,e){return r=t.validate(r),e=t.validate(e),n.add(r,e)},t.prototype.add=function(r){return new t(n.add(this.value,r.getValue()))},t.subtract=function(r,e){return r=t.validate(r),e=t.validate(e),s.subtract(r,e)},t.prototype.subtract=function(r){return new t(s.subtract(this.value,r.getValue()))},t.multiply=function(r,e){return r=t.validate(r),e=t.validate(e),u.multiply(r,e)},t.prototype.multiply=function(r){return new t(u.multiply(this.value,r.getValue()))},t.divide=function(r,e,n){return r=t.validate(r),e=t.validate(e),a.divide(r,e,n)},t.prototype.divide=function(r,e){return new t(a.divide(this.value,r.getValue(),e))},t.compareTo=function(r,e){return r=t.validate(r),e=t.validate(e),o.compareTo(r,e)},t.prototype.compareTo=function(t){return o.compareTo(this.value,t.getValue())},t.negate=function(r){return r=t.validate(r),s.negate(r)},t.prototype.negate=function(){return new t(s.negate(this.value))},t}();t.exports=l},function(t,r,e){"use strict";function n(t,r){t=t.toString(),r=r.toString();var e=0;"-"==t[0]&&(e++,t=t.substr(1)),"-"==r[0]&&(e++,r=r.substr(1)),t=u(t),r=u(r);var n=0,a=0;-1!=t.indexOf(".")&&(n=t.length-t.indexOf(".")-1),-1!=r.indexOf(".")&&(a=r.length-r.indexOf(".")-1);var o=n+a;if(t=u(t.replace(".","")),r=u(r.replace(".","")),t.length<r.length){var s=t;t=r,r=s}if("0"==r)return"0";for(var l=r.length,f=0,g=[],c=l-1,d="",v=0;v<l;v++)g[v]=t.length-1;for(var v=0;v<2*t.length;v++){for(var p=0,h=r.length-1;h>=c&&h>=0;h--)g[h]>-1&&g[h]<t.length&&(p+=parseInt(t[g[h]--])*parseInt(r[h]));p+=f,f=Math.floor(p/10),d=p%10+d,c--}return d=u(i(d,o)),1==e&&(d="-"+d),d}function i(t,r){return 0==r?t:(t=r>=t.length?new Array(r-t.length+1).join("0")+t:t,t.substr(0,t.length-r)+"."+t.substr(t.length-r,r))}function u(t){for(;"0"==t[0];)t=t.substr(1);if(-1!=t.indexOf("."))for(;"0"==t[t.length-1];)t=t.substr(0,t.length-1);return""==t||"."==t?t="0":"."==t[t.length-1]&&(t=t.substr(0,t.length-1)),"."==t[0]&&(t="0"+t),t}Object.defineProperty(r,"__esModule",{value:!0}),r.multiply=n},function(t,r,e){"use strict";function n(t,r,e){if(void 0===e&&(e=8),0==r)throw new Error("Cannot divide by 0");if(t=t.toString(),r=r.toString(),0==t)return"0";var n=0;"-"==r[0]&&(r=r.substring(1),n++),"-"==t[0]&&(t=t.substring(1),n++);var a=r.indexOf(".")>0?r.length-r.indexOf(".")-1:-1;if(r=i.trim(r.replace(".","")),a>=0){var o=t.indexOf(".")>0?t.length-t.indexOf(".")-1:-1;if(-1==o)t=i.trim(t+new Array(a+1).join("0"));else if(a>o)t=t.replace(".",""),t=i.trim(t+new Array(a-o+1).join("0"));else if(a<o){t=t.replace(".","");var s=t.length-a+a;t=i.trim(t.substring(0,s)+"."+t.substring(s))}else a==o&&(t=i.trim(t.replace(".","")))}var l=0,f=r.length,g="",c=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(0,f+1):t.substring(0,f);if(t=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(f+1):t.substring(f),c.indexOf(".")>-1){var d=c.length-c.indexOf(".")-1;c=c.replace(".",""),f>c.length&&(d+=f-c.length,c+=new Array(f-c.length+1).join("0")),l=d,g="0."+new Array(d).join("0")}for(e+=2;l<=e;){for(var v=0;parseInt(c)>=parseInt(r);)c=i.add(c,"-"+r),v++;g+=v,t?("."==t[0]&&(g+=".",l++,t=t.substring(1)),c+=t.substring(0,1),t=t.substring(1)):(l||(g+="."),l++,c+="0")}return(1==n?"-":"")+i.trim(u.roundOff(g,e-2))}Object.defineProperty(r,"__esModule",{value:!0});var i=e(0),u=e(1);r.divide=n},function(t,r,e){"use strict";function n(t,r){var e=!1;if("-"==t[0]&&"-"!=r[0])return-1;if("-"!=t[0]&&"-"==r[0])return 1;if("-"==t[0]&&"-"==r[0]&&(t=t.substr(1),r=r.substr(1),e=!0),u=i.pad(t,r),t=u[0],r=u[1],0==t.localeCompare(r))return 0;for(var n=0;n<t.length;n++)if(t[n]!=r[n])return t[n]>r[n]?e?-1:1:e?1:-1;return 0;var u}Object.defineProperty(r,"__esModule",{value:!0});var i=e(0);r.compareTo=n},function(t,r,e){"use strict";function n(t,r){return t=t.toString(),r=r.toString(),r=i(r),u.add(t,r)}function i(t){return t="-"==t[0]?t.substr(1):"-"+t}Object.defineProperty(r,"__esModule",{value:!0});var u=e(0);r.subtract=n,r.negate=i}]); | ||
var bigDecimal=function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}var e={};return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,e){"use strict";function n(t,r){void 0===r&&(r="0");var e=0,n=-1;"-"==t[0]&&(e++,n=1,t=t.substring(1),t.length),"-"==r[0]&&(e++,n=2,r=r.substring(1),r.length),t=u(t),r=u(r),l=a(u(t),u(r)),t=l[0],r=l[1],1==e&&(1==n?t=i(t):r=i(r));var s=o(t,r);return e?2==e?"-"+u(s):t.length<s.length?u(s.substring(1)):"-"+u(i(s)):u(s);var l}function i(t){for(var r="",e=t.length,n=t.split(".")[1],i=n?n.length:0,u=0;u<e;u++)t[u]>="0"&&t[u]<="9"?r+=9-parseInt(t[u]):r+=t[u];return o(r,i>0?"0."+new Array(i).join("0")+"1":"1")}function u(t){var r=t.split(".");for(r[0]||(r[0]="0");"0"==r[0][0]&&r[0].length>1;)r[0]=r[0].substring(1);return r[0]+(r[1]?"."+r[1]:"")}function a(t,r){var e=t.split("."),n=r.split("."),i=e[0].length,u=n[0].length;return i>u?n[0]=new Array(Math.abs(i-u)+1).join("0")+(n[0]?n[0]:""):e[0]=new Array(Math.abs(i-u)+1).join("0")+(e[0]?e[0]:""),i=e[1]?e[1].length:0,u=n[1]?n[1].length:0,(i||u)&&(i>u?n[1]=(n[1]?n[1]:"")+new Array(Math.abs(i-u)+1).join("0"):e[1]=(e[1]?e[1]:"")+new Array(Math.abs(i-u)+1).join("0")),t=e[0]+(e[1]?"."+e[1]:""),r=n[0]+(n[1]?"."+n[1]:""),[t,r]}function o(t,r){o=a(t,r),t=o[0],r=o[1];for(var e="",n=0,i=t.length-1;i>=0;i--)if("."!==t[i]){var u=parseInt(t[i])+parseInt(r[i])+n;e=u%10+e,n=Math.floor(u/10)}else e="."+e;return n?n.toString()+e:e;var o}Object.defineProperty(r,"__esModule",{value:!0}),r.add=n,r.trim=u,r.pad=a},function(t,r,e){"use strict";function n(t,r){void 0===r&&(r=0),"number"==typeof t&&(t=t.toString());var e=!1;"-"===t[0]&&(e=!0,t=t.substring(1));var a=t.split("."),o=a[0],s=a[1];if(r<0){if(r=-r,o.length<=r)return"0";var l=o.substr(0,o.length-r);return t=l+"."+o.substr(o.length-r)+s,l=n(t),(e?"-":"")+l+new Array(r+1).join("0")}if(0==r){o.length;return i(a[1],o)?(e?"-":"")+u(o):(e?"-":"")+o}if(!a[1])return(e?"-":"")+o+"."+new Array(r+1).join("0");if(a[1].length<r)return(e?"-":"")+o+"."+a[1]+new Array(r-a[1].length+1).join("0");s=a[1].substring(0,r);var f=a[1].substring(r);return f&&i(f,s)&&(s=u(s),s.length>r)?u(o,parseInt(s[0]))+"."+s.substring(1):(e?"-":"")+o+"."+s}function i(t,r){return!!t&&(t>"5"+new Array(t.length+1).join("0")||"5"==t&&parseInt(r[r.length-1])%2==1)}function u(t,r){void 0===r&&(r=0),r||(r=1),"number"==typeof t&&t.toString();for(var e=t.length-1,n="",i=e;i>=0;i--){var u=parseInt(t[i])+r;10==u?(r=1,u=0):r=0,n+=u}return r&&(n+=r),n.split("").reverse().join("")}Object.defineProperty(r,"__esModule",{value:!0}),r.roundOff=n},function(t,r,e){"use strict";var n=e(0),i=e(1),u=e(3),a=e(4),o=e(5),s=e(6),l=function(){function t(r){void 0===r&&(r="0"),this.value=t.validate(r)}return t.validate=function(t){if(t){if(t=t.toString(),isNaN(t))throw Error("Parameter is not a number: "+t);"+"==t[0]&&(t=t.substring(1))}else t="0";if(/e/i.test(t)){var r=t.split(/[eE]/),e=r[0],i=r[1];e=n.trim(e),i=parseInt(i)+e.indexOf("."),e=e.replace(".",""),t=e.length<i?e+new Array(i-e.length+1).join("0"):e.length>=i&&i>0?n.trim(e.substring(0,i))+(e.length>i?"."+e.substring(i):""):"0."+new Array(1-i).join("0")+e}return t},t.prototype.getValue=function(){return this.value},t.getPrettyValue=function(r,e,n){if(e||n){if(!e||!n)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else e=3,n=",";r=t.validate(r);var i="-"==r.charAt(0);i&&(r=r.substring(1));var u=r.indexOf(".");u=u>0?u:r.length;for(var a="",o=u;o>0;)o<e?(e=o,o=0):o-=e,a=r.substring(o,o+e)+(o<u-e&&o>=0?n:"")+a;return(i?"-":"")+a+r.substring(u)},t.prototype.getPrettyValue=function(r,e){return t.getPrettyValue(this.value,r,e)},t.round=function(r,e){if(void 0===e&&(e=0),r=t.validate(r),isNaN(e))throw Error("Precision is not a number: "+e);return i.roundOff(r,e)},t.prototype.round=function(r){if(void 0===r&&(r=0),isNaN(r))throw Error("Precision is not a number: "+r);return new t(i.roundOff(this.value,r))},t.floor=function(r){return r=t.validate(r),-1===r.indexOf(".")?r:t.round(t.subtract(r,.5))},t.prototype.floor=function(){return-1===this.value.indexOf(".")?new t(this.value):this.subtract(new t(.5)).round()},t.ceil=function(r){return r=t.validate(r),-1===r.indexOf(".")?r:t.round(t.add(r,.5))},t.prototype.ceil=function(){return-1===this.value.indexOf(".")?new t(this.value):this.add(new t(.5)).round()},t.add=function(r,e){return r=t.validate(r),e=t.validate(e),n.add(r,e)},t.prototype.add=function(r){return new t(n.add(this.value,r.getValue()))},t.subtract=function(r,e){return r=t.validate(r),e=t.validate(e),s.subtract(r,e)},t.prototype.subtract=function(r){return new t(s.subtract(this.value,r.getValue()))},t.multiply=function(r,e){return r=t.validate(r),e=t.validate(e),u.multiply(r,e)},t.prototype.multiply=function(r){return new t(u.multiply(this.value,r.getValue()))},t.divide=function(r,e,n){return r=t.validate(r),e=t.validate(e),a.divide(r,e,n)},t.prototype.divide=function(r,e){return new t(a.divide(this.value,r.getValue(),e))},t.compareTo=function(r,e){return r=t.validate(r),e=t.validate(e),o.compareTo(r,e)},t.prototype.compareTo=function(t){return o.compareTo(this.value,t.getValue())},t.negate=function(r){return r=t.validate(r),s.negate(r)},t.prototype.negate=function(){return new t(s.negate(this.value))},t}();t.exports=l},function(t,r,e){"use strict";function n(t,r){t=t.toString(),r=r.toString();var e=0;"-"==t[0]&&(e++,t=t.substr(1)),"-"==r[0]&&(e++,r=r.substr(1)),t=u(t),r=u(r);var n=0,a=0;-1!=t.indexOf(".")&&(n=t.length-t.indexOf(".")-1),-1!=r.indexOf(".")&&(a=r.length-r.indexOf(".")-1);var o=n+a;if(t=u(t.replace(".","")),r=u(r.replace(".","")),t.length<r.length){var s=t;t=r,r=s}if("0"==r)return"0";for(var l=r.length,f=0,g=[],d=l-1,c="",v=0;v<l;v++)g[v]=t.length-1;for(var v=0;v<2*t.length;v++){for(var h=0,p=r.length-1;p>=d&&p>=0;p--)g[p]>-1&&g[p]<t.length&&(h+=parseInt(t[g[p]--])*parseInt(r[p]));h+=f,f=Math.floor(h/10),c=h%10+c,d--}return c=u(i(c,o)),1==e&&(c="-"+c),c}function i(t,r){return 0==r?t:(t=r>=t.length?new Array(r-t.length+1).join("0")+t:t,t.substr(0,t.length-r)+"."+t.substr(t.length-r,r))}function u(t){for(;"0"==t[0];)t=t.substr(1);if(-1!=t.indexOf("."))for(;"0"==t[t.length-1];)t=t.substr(0,t.length-1);return""==t||"."==t?t="0":"."==t[t.length-1]&&(t=t.substr(0,t.length-1)),"."==t[0]&&(t="0"+t),t}Object.defineProperty(r,"__esModule",{value:!0}),r.multiply=n},function(t,r,e){"use strict";function n(t,r,e){if(void 0===e&&(e=8),0==r)throw new Error("Cannot divide by 0");if(t=t.toString(),r=r.toString(),0==t)return"0";var n=0;"-"==r[0]&&(r=r.substring(1),n++),"-"==t[0]&&(t=t.substring(1),n++);var a=r.indexOf(".")>0?r.length-r.indexOf(".")-1:-1;if(r=i.trim(r.replace(".","")),a>=0){var o=t.indexOf(".")>0?t.length-t.indexOf(".")-1:-1;if(-1==o)t=i.trim(t+new Array(a+1).join("0"));else if(a>o)t=t.replace(".",""),t=i.trim(t+new Array(a-o+1).join("0"));else if(a<o){t=t.replace(".","");var s=t.length-a+a;t=i.trim(t.substring(0,s)+"."+t.substring(s))}else a==o&&(t=i.trim(t.replace(".","")))}var l=0,f=r.length,g="",d=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(0,f+1):t.substring(0,f);if(t=t.indexOf(".")>-1&&t.indexOf(".")<f?t.substring(f+1):t.substring(f),d.indexOf(".")>-1){var c=d.length-d.indexOf(".")-1;d=d.replace(".",""),f>d.length&&(c+=f-d.length,d+=new Array(f-d.length+1).join("0")),l=c,g="0."+new Array(c).join("0")}for(e+=2;l<=e;){for(var v=0;parseInt(d)>=parseInt(r);)d=i.add(d,"-"+r),v++;g+=v,t?("."==t[0]&&(g+=".",l++,t=t.substring(1)),d+=t.substring(0,1),t=t.substring(1)):(l||(g+="."),l++,d+="0")}return(1==n?"-":"")+i.trim(u.roundOff(g,e-2))}Object.defineProperty(r,"__esModule",{value:!0});var i=e(0),u=e(1);r.divide=n},function(t,r,e){"use strict";function n(t,r){var e=!1;if("-"==t[0]&&"-"!=r[0])return-1;if("-"!=t[0]&&"-"==r[0])return 1;if("-"==t[0]&&"-"==r[0]&&(t=t.substr(1),r=r.substr(1),e=!0),u=i.pad(t,r),t=u[0],r=u[1],0==t.localeCompare(r))return 0;for(var n=0;n<t.length;n++)if(t[n]!=r[n])return t[n]>r[n]?e?-1:1:e?1:-1;return 0;var u}Object.defineProperty(r,"__esModule",{value:!0});var i=e(0);r.compareTo=n},function(t,r,e){"use strict";function n(t,r){return t=t.toString(),r=r.toString(),r=i(r),u.add(t,r)}function i(t){return t="-"==t[0]?t.substr(1):"-"+t}Object.defineProperty(r,"__esModule",{value:!0});var u=e(0);r.subtract=n,r.negate=i}]); |
{ | ||
"name": "js-big-decimal", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "Work with large numbers on the client side. Round them off to any required precission.", | ||
@@ -9,4 +9,5 @@ "main": "dist/node/js-big-decimal", | ||
"test": "./node_modules/.bin/jasmine JASMINE_CONFIG_PATH=spec/jasmine.json --helper=spec/helper/*.js", | ||
"test:watch": "chokidar \"lib/**/*.js\" -c \"npm run travis-test\"", | ||
"travis-test": "./node_modules/.bin/jasmine JASMINE_CONFIG_PATH=spec/jasmine.json", | ||
"test:watch": "chokidar \"src/**/*.ts\" -c \"npm run travis-test\"", | ||
"pretravis-test": "tsc", | ||
"travis-test": "jasmine-ts JASMINE_CONFIG_PATH=spec/jasmine.json", | ||
"test-random": "node test/randomtest.js", | ||
@@ -49,2 +50,4 @@ "compile": "tsc", | ||
"devDependencies": { | ||
"@types/jasmine": "^2.5.53", | ||
"@types/node": "^8.0.17", | ||
"del": "^3.0.0", | ||
@@ -55,2 +58,3 @@ "glob": "^7.1.2", | ||
"jasmine-spec-reporter": "^4.1.1", | ||
"jasmine-ts": "^0.2.0", | ||
"webpack": "^3.4.0" | ||
@@ -57,0 +61,0 @@ }, |
@@ -23,2 +23,4 @@ # JS Big Decimal | ||
- [round(number, precision)](#roundnumber-precision) | ||
- [floor(number)](#floornumber) | ||
- [ceil(number)](#ceilnumber) | ||
- [compareTo(number1, number2)](#comparetonumber1-number2) | ||
@@ -106,5 +108,29 @@ - [negate(number)](#negatenumber) | ||
var val2 = bigDecimal.round("587", -1); // val2 = "590" | ||
var val1 = bigDecimal.round("123.78", -4); // val3 = "0" | ||
var val3 = bigDecimal.round("123.78", -4); // val3 = "0" | ||
``` | ||
### floor(number) | ||
Returns the whole number nearest but not greater than the input number. | ||
```javascript | ||
var n1 = bigDecimal.floor(12.8) // "12" | ||
var n2 = bigDecimal.floor(-12.3) // "-13" | ||
``` | ||
The instance function returns the result as a new `bigDecimal` | ||
```javascript | ||
var n1 = new bigDecimal(12.8).floor() // bigDecimal(12) | ||
var n2 = bigDecimal(-12.3).floor() // bigDecimal(-13) | ||
``` | ||
### ceil(number) | ||
Returns the whole number nearest but not lesser than the input number. | ||
```javascript | ||
var n1 = bigDecimal.ceil(12.8) // "13" | ||
var n2 = bigDecimal.ceil(-12.3) // "-12" | ||
``` | ||
The instance function returns the result as a new `bigDecimal` | ||
```javascript | ||
var n1 = new bigDecimal(12.8).ceil() // bigDecimal(13) | ||
var n2 = bigDecimal(-12.3).ceil() // bigDecimal(-12) | ||
``` | ||
### compareTo(number1, number2) | ||
@@ -111,0 +137,0 @@ Compare two numbers. Returns `1, 0 and -1` if `number1 > number2, number1 == number2 and number1 < number2` respectively. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124265
12
1389
207
9