Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-big-decimal

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-big-decimal - npm Package Compare versions

Comparing version 1.1.8 to 1.2.0

6

dist/node/big-decimal.d.ts

@@ -0,3 +1,5 @@

import { RoundingModes as Modes } from './roundingModes';
declare class bigDecimal {
private value;
static RoundingModes: typeof Modes;
private static validate(number);

@@ -8,4 +10,4 @@ constructor(number?: number | string);

getPrettyValue(digits: any, separator: any): string;
static round(number: any, precision?: number): string;
round(precision?: number): bigDecimal;
static round(number: any, precision?: number, mode?: Modes): string;
round(precision?: number, mode?: Modes): bigDecimal;
static floor(number: any): any;

@@ -12,0 +14,0 @@ floor(): bigDecimal;

@@ -73,3 +73,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })

@@ -194,4 +194,15 @@ /************************************************************************/

Object.defineProperty(exports, "__esModule", { value: true });
function roundOff(input, n) {
var roundingModes_1 = __webpack_require__(2);
/**
*
* @param input the number to round
* @param n precision
* @param mode Rounding Mode
*/
function roundOff(input, n, mode) {
if (n === void 0) { n = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
if (mode === roundingModes_1.RoundingModes.UNNECESSARY) {
throw new Error("UNNECESSARY Rounding Mode has not yet been implemented");
}
if (typeof (input) == 'number')

@@ -205,3 +216,3 @@ input = input.toString();

var parts = input.split('.'), partInt = parts[0], partDec = parts[1];
//handle case of -ve n
//handle case of -ve n: roundOff(12564,-2)=12600
if (n < 0) {

@@ -214,9 +225,10 @@ n = -n;

input = prefix + '.' + partInt.substr(partInt.length - n) + partDec;
prefix = roundOff(input);
prefix = roundOff(input, 0, mode);
return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0'));
}
}
// handle case when integer output is desired
if (n == 0) {
var l = partInt.length;
if (greaterThanFive(parts[1], partInt)) {
if (greaterThanFive(parts[1], partInt, neg, mode)) {
return (neg ? '-' : '') + increment(partInt);

@@ -226,2 +238,3 @@ }

}
// handle case when n>0
if (!parts[1]) {

@@ -235,3 +248,3 @@ return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0'));

var rem = parts[1].substring(n);
if (rem && greaterThanFive(rem, partDec)) {
if (rem && greaterThanFive(rem, partDec, neg, mode)) {
partDec = increment(partDec);

@@ -245,7 +258,26 @@ if (partDec.length > n) {

exports.roundOff = roundOff;
function greaterThanFive(part, pre) {
if (!part)
function greaterThanFive(part, pre, neg, mode) {
if (!part || part === new Array(part.length + 1).join('0'))
return false;
var five = '5' + (new Array(part.length + 1).join('0'));
return (part > five || (part == '5' && parseInt(pre[pre.length - 1]) % 2 == 1));
// #region UP, DOWN, CEILING, FLOOR
if (mode === roundingModes_1.RoundingModes.DOWN || (!neg && mode === roundingModes_1.RoundingModes.FLOOR) ||
(neg && mode === roundingModes_1.RoundingModes.CEILING))
return false;
if (mode === roundingModes_1.RoundingModes.UP || (neg && mode === roundingModes_1.RoundingModes.FLOOR) ||
(!neg && mode === roundingModes_1.RoundingModes.CEILING))
return true;
// #endregion
// case when part !== five
var five = '5' + (new Array(part.length).join('0'));
if (part > five)
return true;
else if (part < five)
return false;
// case when part === five
switch (mode) {
case roundingModes_1.RoundingModes.HALF_DOWN: return false;
case roundingModes_1.RoundingModes.HALF_UP: return true;
case roundingModes_1.RoundingModes.HALF_EVEN:
default: return (parseInt(pre[pre.length - 1]) % 2 == 1);
}
}

@@ -282,8 +314,50 @@ function increment(part, c) {

Object.defineProperty(exports, "__esModule", { value: true });
/**
* CEILING
* Rounding mode to round towards positive infinity.
* DOWN
* Rounding mode to round towards zero.
* FLOOR
* Rounding mode to round towards negative infinity.
* HALF_DOWN
* Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant,
* in which case round down.
* HALF_EVEN
* Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant,
* in which case, round towards the even neighbor.
* HALF_UP
* Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant,
* in which case round up.
* UNNECESSARY
* Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
* UP
* Rounding mode to round away from zero.
*/
var RoundingModes;
(function (RoundingModes) {
RoundingModes[RoundingModes["CEILING"] = 0] = "CEILING";
RoundingModes[RoundingModes["DOWN"] = 1] = "DOWN";
RoundingModes[RoundingModes["FLOOR"] = 2] = "FLOOR";
RoundingModes[RoundingModes["HALF_DOWN"] = 3] = "HALF_DOWN";
RoundingModes[RoundingModes["HALF_EVEN"] = 4] = "HALF_EVEN";
RoundingModes[RoundingModes["HALF_UP"] = 5] = "HALF_UP";
RoundingModes[RoundingModes["UNNECESSARY"] = 6] = "UNNECESSARY";
RoundingModes[RoundingModes["UP"] = 7] = "UP";
})(RoundingModes = exports.RoundingModes || (exports.RoundingModes = {}));
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var add_1 = __webpack_require__(0);
var round_1 = __webpack_require__(1);
var multiply_1 = __webpack_require__(3);
var divide_1 = __webpack_require__(4);
var compareTo_1 = __webpack_require__(5);
var subtract_1 = __webpack_require__(6);
var multiply_1 = __webpack_require__(4);
var divide_1 = __webpack_require__(5);
var compareTo_1 = __webpack_require__(6);
var subtract_1 = __webpack_require__(7);
var roundingModes_1 = __webpack_require__(2);
var bigDecimal = (function () {

@@ -355,14 +429,16 @@ function bigDecimal(number) {

};
bigDecimal.round = function (number, precision) {
bigDecimal.round = function (number, precision, mode) {
if (precision === void 0) { precision = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
number = bigDecimal.validate(number);
if (isNaN(precision))
throw Error("Precision is not a number: " + precision);
return round_1.roundOff(number, precision);
return round_1.roundOff(number, precision, mode);
};
bigDecimal.prototype.round = function (precision) {
bigDecimal.prototype.round = function (precision, mode) {
if (precision === void 0) { precision = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
if (isNaN(precision))
throw Error("Precision is not a number: " + precision);
return new bigDecimal(round_1.roundOff(this.value, precision));
return new bigDecimal(round_1.roundOff(this.value, precision, mode));
};

@@ -438,2 +514,3 @@ bigDecimal.floor = function (number) {

};
bigDecimal.RoundingModes = roundingModes_1.RoundingModes;
return bigDecimal;

@@ -445,3 +522,3 @@ }());

/***/ }),
/* 3 */
/* 4 */
/***/ (function(module, exports, __webpack_require__) {

@@ -555,3 +632,3 @@

/***/ }),
/* 4 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {

@@ -647,3 +724,3 @@

/***/ }),
/* 5 */
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

@@ -700,3 +777,3 @@

/***/ }),
/* 6 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {

@@ -703,0 +780,0 @@

@@ -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=!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}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.bigDecimal=t():e.bigDecimal=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,n){"use strict";function r(e,t){void 0===t&&(t="0");var n=0,r=-1;"-"==e[0]&&(n++,r=1,e=e.substring(1),e.length),"-"==t[0]&&(n++,r=2,t=t.substring(1),t.length),e=o(e),t=o(t),l=u(o(e),o(t)),e=l[0],t=l[1],1==n&&(1==r?e=i(e):t=i(t));var s=a(e,t);return n?2==n?"-"+o(s):e.length<s.length?o(s.substring(1)):"-"+o(i(s)):o(s);var l}function i(e){for(var t="",n=e.length,r=e.split(".")[1],i=r?r.length:0,o=0;o<n;o++)e[o]>="0"&&e[o]<="9"?t+=9-parseInt(e[o]):t+=e[o];return a(t,i>0?"0."+new Array(i).join("0")+"1":"1")}function o(e){var t=e.split(".");for(t[0]||(t[0]="0");"0"==t[0][0]&&t[0].length>1;)t[0]=t[0].substring(1);return t[0]+(t[1]?"."+t[1]:"")}function u(e,t){var n=e.split("."),r=t.split("."),i=n[0].length,o=r[0].length;return i>o?r[0]=new Array(Math.abs(i-o)+1).join("0")+(r[0]?r[0]:""):n[0]=new Array(Math.abs(i-o)+1).join("0")+(n[0]?n[0]:""),i=n[1]?n[1].length:0,o=r[1]?r[1].length:0,(i||o)&&(i>o?r[1]=(r[1]?r[1]:"")+new Array(Math.abs(i-o)+1).join("0"):n[1]=(n[1]?n[1]:"")+new Array(Math.abs(i-o)+1).join("0")),e=n[0]+(n[1]?"."+n[1]:""),t=r[0]+(r[1]?"."+r[1]:""),[e,t]}function a(e,t){a=u(e,t),e=a[0],t=a[1];for(var n="",r=0,i=e.length-1;i>=0;i--)if("."!==e[i]){var o=parseInt(e[i])+parseInt(t[i])+r;n=o%10+n,r=Math.floor(o/10)}else n="."+n;return r?r.toString()+n:n;var a}Object.defineProperty(t,"__esModule",{value:!0}),t.add=r,t.trim=o,t.pad=u},function(e,t,n){"use strict";function r(e,t,n){if(void 0===t&&(t=0),void 0===n&&(n=u.RoundingModes.HALF_EVEN),n===u.RoundingModes.UNNECESSARY)throw new Error("UNNECESSARY Rounding Mode has not yet been implemented");"number"==typeof e&&(e=e.toString());var a=!1;"-"===e[0]&&(a=!0,e=e.substring(1));var s=e.split("."),l=s[0],f=s[1];if(t<0){if(t=-t,l.length<=t)return"0";var d=l.substr(0,l.length-t);return e=d+"."+l.substr(l.length-t)+f,d=r(e,0,n),(a?"-":"")+d+new Array(t+1).join("0")}if(0==t){l.length;return i(s[1],l,a,n)?(a?"-":"")+o(l):(a?"-":"")+l}if(!s[1])return(a?"-":"")+l+"."+new Array(t+1).join("0");if(s[1].length<t)return(a?"-":"")+l+"."+s[1]+new Array(t-s[1].length+1).join("0");f=s[1].substring(0,t);var g=s[1].substring(t);return g&&i(g,f,a,n)&&(f=o(f),f.length>t)?o(l,parseInt(f[0]))+"."+f.substring(1):(a?"-":"")+l+"."+f}function i(e,t,n,r){if(!e||e===new Array(e.length+1).join("0"))return!1;if(r===u.RoundingModes.DOWN||!n&&r===u.RoundingModes.FLOOR||n&&r===u.RoundingModes.CEILING)return!1;if(r===u.RoundingModes.UP||n&&r===u.RoundingModes.FLOOR||!n&&r===u.RoundingModes.CEILING)return!0;var i="5"+new Array(e.length).join("0");if(e>i)return!0;if(e<i)return!1;switch(r){case u.RoundingModes.HALF_DOWN:return!1;case u.RoundingModes.HALF_UP:return!0;case u.RoundingModes.HALF_EVEN:default:return parseInt(t[t.length-1])%2==1}}function o(e,t){void 0===t&&(t=0),t||(t=1),"number"==typeof e&&e.toString();for(var n=e.length-1,r="",i=n;i>=0;i--){var o=parseInt(e[i])+t;10==o?(t=1,o=0):t=0,r+=o}return t&&(r+=t),r.split("").reverse().join("")}Object.defineProperty(t,"__esModule",{value:!0});var u=n(2);t.roundOff=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.CEILING=0]="CEILING",e[e.DOWN=1]="DOWN",e[e.FLOOR=2]="FLOOR",e[e.HALF_DOWN=3]="HALF_DOWN",e[e.HALF_EVEN=4]="HALF_EVEN",e[e.HALF_UP=5]="HALF_UP",e[e.UNNECESSARY=6]="UNNECESSARY",e[e.UP=7]="UP"}(t.RoundingModes||(t.RoundingModes={}))},function(e,t,n){"use strict";var r=n(0),i=n(1),o=n(4),u=n(5),a=n(6),s=n(7),l=n(2),f=function(){function e(t){void 0===t&&(t="0"),this.value=e.validate(t)}return e.validate=function(e){if(e){if(e=e.toString(),isNaN(e))throw Error("Parameter is not a number: "+e);"+"==e[0]&&(e=e.substring(1))}else e="0";if(/e/i.test(e)){var t=e.split(/[eE]/),n=t[0],i=t[1];n=r.trim(n),i=parseInt(i)+n.indexOf("."),n=n.replace(".",""),e=n.length<i?n+new Array(i-n.length+1).join("0"):n.length>=i&&i>0?r.trim(n.substring(0,i))+(n.length>i?"."+n.substring(i):""):"0."+new Array(1-i).join("0")+n}return e},e.prototype.getValue=function(){return this.value},e.getPrettyValue=function(t,n,r){if(n||r){if(!n||!r)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else n=3,r=",";t=e.validate(t);var i="-"==t.charAt(0);i&&(t=t.substring(1));var o=t.indexOf(".");o=o>0?o:t.length;for(var u="",a=o;a>0;)a<n?(n=a,a=0):a-=n,u=t.substring(a,a+n)+(a<o-n&&a>=0?r:"")+u;return(i?"-":"")+u+t.substring(o)},e.prototype.getPrettyValue=function(t,n){return e.getPrettyValue(this.value,t,n)},e.round=function(t,n,r){if(void 0===n&&(n=0),void 0===r&&(r=l.RoundingModes.HALF_EVEN),t=e.validate(t),isNaN(n))throw Error("Precision is not a number: "+n);return i.roundOff(t,n,r)},e.prototype.round=function(t,n){if(void 0===t&&(t=0),void 0===n&&(n=l.RoundingModes.HALF_EVEN),isNaN(t))throw Error("Precision is not a number: "+t);return new e(i.roundOff(this.value,t,n))},e.floor=function(t){return t=e.validate(t),-1===t.indexOf(".")?t:e.round(e.subtract(t,.5))},e.prototype.floor=function(){return-1===this.value.indexOf(".")?new e(this.value):this.subtract(new e(.5)).round()},e.ceil=function(t){return t=e.validate(t),-1===t.indexOf(".")?t:e.round(e.add(t,.5))},e.prototype.ceil=function(){return-1===this.value.indexOf(".")?new e(this.value):this.add(new e(.5)).round()},e.add=function(t,n){return t=e.validate(t),n=e.validate(n),r.add(t,n)},e.prototype.add=function(t){return new e(r.add(this.value,t.getValue()))},e.subtract=function(t,n){return t=e.validate(t),n=e.validate(n),s.subtract(t,n)},e.prototype.subtract=function(t){return new e(s.subtract(this.value,t.getValue()))},e.multiply=function(t,n){return t=e.validate(t),n=e.validate(n),o.multiply(t,n)},e.prototype.multiply=function(t){return new e(o.multiply(this.value,t.getValue()))},e.divide=function(t,n,r){return t=e.validate(t),n=e.validate(n),u.divide(t,n,r)},e.prototype.divide=function(t,n){return new e(u.divide(this.value,t.getValue(),n))},e.compareTo=function(t,n){return t=e.validate(t),n=e.validate(n),a.compareTo(t,n)},e.prototype.compareTo=function(e){return a.compareTo(this.value,e.getValue())},e.negate=function(t){return t=e.validate(t),s.negate(t)},e.prototype.negate=function(){return new e(s.negate(this.value))},e.RoundingModes=l.RoundingModes,e}();e.exports=f},function(e,t,n){"use strict";function r(e,t){e=e.toString(),t=t.toString();var n=0;"-"==e[0]&&(n++,e=e.substr(1)),"-"==t[0]&&(n++,t=t.substr(1)),e=o(e),t=o(t);var r=0,u=0;-1!=e.indexOf(".")&&(r=e.length-e.indexOf(".")-1),-1!=t.indexOf(".")&&(u=t.length-t.indexOf(".")-1);var a=r+u;if(e=o(e.replace(".","")),t=o(t.replace(".","")),e.length<t.length){var s=e;e=t,t=s}if("0"==t)return"0";for(var l=t.length,f=0,d=[],g=l-1,c="",v=0;v<l;v++)d[v]=e.length-1;for(var v=0;v<2*e.length;v++){for(var p=0,h=t.length-1;h>=g&&h>=0;h--)d[h]>-1&&d[h]<e.length&&(p+=parseInt(e[d[h]--])*parseInt(t[h]));p+=f,f=Math.floor(p/10),c=p%10+c,g--}return c=o(i(c,a)),1==n&&(c="-"+c),c}function i(e,t){return 0==t?e:(e=t>=e.length?new Array(t-e.length+1).join("0")+e:e,e.substr(0,e.length-t)+"."+e.substr(e.length-t,t))}function o(e){for(;"0"==e[0];)e=e.substr(1);if(-1!=e.indexOf("."))for(;"0"==e[e.length-1];)e=e.substr(0,e.length-1);return""==e||"."==e?e="0":"."==e[e.length-1]&&(e=e.substr(0,e.length-1)),"."==e[0]&&(e="0"+e),e}Object.defineProperty(t,"__esModule",{value:!0}),t.multiply=r},function(e,t,n){"use strict";function r(e,t,n){if(void 0===n&&(n=8),0==t)throw new Error("Cannot divide by 0");if(e=e.toString(),t=t.toString(),0==e)return"0";var r=0;"-"==t[0]&&(t=t.substring(1),r++),"-"==e[0]&&(e=e.substring(1),r++);var u=t.indexOf(".")>0?t.length-t.indexOf(".")-1:-1;if(t=i.trim(t.replace(".","")),u>=0){var a=e.indexOf(".")>0?e.length-e.indexOf(".")-1:-1;if(-1==a)e=i.trim(e+new Array(u+1).join("0"));else if(u>a)e=e.replace(".",""),e=i.trim(e+new Array(u-a+1).join("0"));else if(u<a){e=e.replace(".","");var s=e.length-u+u;e=i.trim(e.substring(0,s)+"."+e.substring(s))}else u==a&&(e=i.trim(e.replace(".","")))}var l=0,f=t.length,d="",g=e.indexOf(".")>-1&&e.indexOf(".")<f?e.substring(0,f+1):e.substring(0,f);if(e=e.indexOf(".")>-1&&e.indexOf(".")<f?e.substring(f+1):e.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(n+=2;l<=n;){for(var v=0;parseInt(g)>=parseInt(t);)g=i.add(g,"-"+t),v++;d+=v,e?("."==e[0]&&(d+=".",l++,e=e.substring(1)),g+=e.substring(0,1),e=e.substring(1)):(l||(d+="."),l++,g+="0")}return(1==r?"-":"")+i.trim(o.roundOff(d,n-2))}Object.defineProperty(t,"__esModule",{value:!0});var i=n(0),o=n(1);t.divide=r},function(e,t,n){"use strict";function r(e,t){var n=!1;if("-"==e[0]&&"-"!=t[0])return-1;if("-"!=e[0]&&"-"==t[0])return 1;if("-"==e[0]&&"-"==t[0]&&(e=e.substr(1),t=t.substr(1),n=!0),o=i.pad(e,t),e=o[0],t=o[1],0==e.localeCompare(t))return 0;for(var r=0;r<e.length;r++)if(e[r]!=t[r])return e[r]>t[r]?n?-1:1:n?1:-1;return 0;var o}Object.defineProperty(t,"__esModule",{value:!0});var i=n(0);t.compareTo=r},function(e,t,n){"use strict";function r(e,t){return e=e.toString(),t=t.toString(),t=i(t),o.add(e,t)}function i(e){return e="-"==e[0]?e.substr(1):"-"+e}Object.defineProperty(t,"__esModule",{value:!0});var o=n(0);t.subtract=r,t.negate=i}])});

@@ -64,3 +64,3 @@ var bigDecimal =

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })

@@ -185,4 +185,15 @@ /************************************************************************/

Object.defineProperty(exports, "__esModule", { value: true });
function roundOff(input, n) {
var roundingModes_1 = __webpack_require__(2);
/**
*
* @param input the number to round
* @param n precision
* @param mode Rounding Mode
*/
function roundOff(input, n, mode) {
if (n === void 0) { n = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
if (mode === roundingModes_1.RoundingModes.UNNECESSARY) {
throw new Error("UNNECESSARY Rounding Mode has not yet been implemented");
}
if (typeof (input) == 'number')

@@ -196,3 +207,3 @@ input = input.toString();

var parts = input.split('.'), partInt = parts[0], partDec = parts[1];
//handle case of -ve n
//handle case of -ve n: roundOff(12564,-2)=12600
if (n < 0) {

@@ -205,9 +216,10 @@ n = -n;

input = prefix + '.' + partInt.substr(partInt.length - n) + partDec;
prefix = roundOff(input);
prefix = roundOff(input, 0, mode);
return (neg ? '-' : '') + prefix + (new Array(n + 1).join('0'));
}
}
// handle case when integer output is desired
if (n == 0) {
var l = partInt.length;
if (greaterThanFive(parts[1], partInt)) {
if (greaterThanFive(parts[1], partInt, neg, mode)) {
return (neg ? '-' : '') + increment(partInt);

@@ -217,2 +229,3 @@ }

}
// handle case when n>0
if (!parts[1]) {

@@ -226,3 +239,3 @@ return (neg ? '-' : '') + partInt + '.' + (new Array(n + 1).join('0'));

var rem = parts[1].substring(n);
if (rem && greaterThanFive(rem, partDec)) {
if (rem && greaterThanFive(rem, partDec, neg, mode)) {
partDec = increment(partDec);

@@ -236,7 +249,26 @@ if (partDec.length > n) {

exports.roundOff = roundOff;
function greaterThanFive(part, pre) {
if (!part)
function greaterThanFive(part, pre, neg, mode) {
if (!part || part === new Array(part.length + 1).join('0'))
return false;
var five = '5' + (new Array(part.length + 1).join('0'));
return (part > five || (part == '5' && parseInt(pre[pre.length - 1]) % 2 == 1));
// #region UP, DOWN, CEILING, FLOOR
if (mode === roundingModes_1.RoundingModes.DOWN || (!neg && mode === roundingModes_1.RoundingModes.FLOOR) ||
(neg && mode === roundingModes_1.RoundingModes.CEILING))
return false;
if (mode === roundingModes_1.RoundingModes.UP || (neg && mode === roundingModes_1.RoundingModes.FLOOR) ||
(!neg && mode === roundingModes_1.RoundingModes.CEILING))
return true;
// #endregion
// case when part !== five
var five = '5' + (new Array(part.length).join('0'));
if (part > five)
return true;
else if (part < five)
return false;
// case when part === five
switch (mode) {
case roundingModes_1.RoundingModes.HALF_DOWN: return false;
case roundingModes_1.RoundingModes.HALF_UP: return true;
case roundingModes_1.RoundingModes.HALF_EVEN:
default: return (parseInt(pre[pre.length - 1]) % 2 == 1);
}
}

@@ -273,8 +305,50 @@ function increment(part, c) {

Object.defineProperty(exports, "__esModule", { value: true });
/**
* CEILING
* Rounding mode to round towards positive infinity.
* DOWN
* Rounding mode to round towards zero.
* FLOOR
* Rounding mode to round towards negative infinity.
* HALF_DOWN
* Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant,
* in which case round down.
* HALF_EVEN
* Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant,
* in which case, round towards the even neighbor.
* HALF_UP
* Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant,
* in which case round up.
* UNNECESSARY
* Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
* UP
* Rounding mode to round away from zero.
*/
var RoundingModes;
(function (RoundingModes) {
RoundingModes[RoundingModes["CEILING"] = 0] = "CEILING";
RoundingModes[RoundingModes["DOWN"] = 1] = "DOWN";
RoundingModes[RoundingModes["FLOOR"] = 2] = "FLOOR";
RoundingModes[RoundingModes["HALF_DOWN"] = 3] = "HALF_DOWN";
RoundingModes[RoundingModes["HALF_EVEN"] = 4] = "HALF_EVEN";
RoundingModes[RoundingModes["HALF_UP"] = 5] = "HALF_UP";
RoundingModes[RoundingModes["UNNECESSARY"] = 6] = "UNNECESSARY";
RoundingModes[RoundingModes["UP"] = 7] = "UP";
})(RoundingModes = exports.RoundingModes || (exports.RoundingModes = {}));
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var add_1 = __webpack_require__(0);
var round_1 = __webpack_require__(1);
var multiply_1 = __webpack_require__(3);
var divide_1 = __webpack_require__(4);
var compareTo_1 = __webpack_require__(5);
var subtract_1 = __webpack_require__(6);
var multiply_1 = __webpack_require__(4);
var divide_1 = __webpack_require__(5);
var compareTo_1 = __webpack_require__(6);
var subtract_1 = __webpack_require__(7);
var roundingModes_1 = __webpack_require__(2);
var bigDecimal = (function () {

@@ -346,14 +420,16 @@ function bigDecimal(number) {

};
bigDecimal.round = function (number, precision) {
bigDecimal.round = function (number, precision, mode) {
if (precision === void 0) { precision = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
number = bigDecimal.validate(number);
if (isNaN(precision))
throw Error("Precision is not a number: " + precision);
return round_1.roundOff(number, precision);
return round_1.roundOff(number, precision, mode);
};
bigDecimal.prototype.round = function (precision) {
bigDecimal.prototype.round = function (precision, mode) {
if (precision === void 0) { precision = 0; }
if (mode === void 0) { mode = roundingModes_1.RoundingModes.HALF_EVEN; }
if (isNaN(precision))
throw Error("Precision is not a number: " + precision);
return new bigDecimal(round_1.roundOff(this.value, precision));
return new bigDecimal(round_1.roundOff(this.value, precision, mode));
};

@@ -429,2 +505,3 @@ bigDecimal.floor = function (number) {

};
bigDecimal.RoundingModes = roundingModes_1.RoundingModes;
return bigDecimal;

@@ -436,3 +513,3 @@ }());

/***/ }),
/* 3 */
/* 4 */
/***/ (function(module, exports, __webpack_require__) {

@@ -546,3 +623,3 @@

/***/ }),
/* 4 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {

@@ -638,3 +715,3 @@

/***/ }),
/* 5 */
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

@@ -691,3 +768,3 @@

/***/ }),
/* 6 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {

@@ -694,0 +771,0 @@

@@ -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=!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}]);
var bigDecimal=function(t){function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var e={};return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=3)}([function(t,n,e){"use strict";function r(t,n){void 0===n&&(n="0");var e=0,r=-1;"-"==t[0]&&(e++,r=1,t=t.substring(1),t.length),"-"==n[0]&&(e++,r=2,n=n.substring(1),n.length),t=u(t),n=u(n),l=o(u(t),u(n)),t=l[0],n=l[1],1==e&&(1==r?t=i(t):n=i(n));var s=a(t,n);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 n="",e=t.length,r=t.split(".")[1],i=r?r.length:0,u=0;u<e;u++)t[u]>="0"&&t[u]<="9"?n+=9-parseInt(t[u]):n+=t[u];return a(n,i>0?"0."+new Array(i).join("0")+"1":"1")}function u(t){var n=t.split(".");for(n[0]||(n[0]="0");"0"==n[0][0]&&n[0].length>1;)n[0]=n[0].substring(1);return n[0]+(n[1]?"."+n[1]:"")}function o(t,n){var e=t.split("."),r=n.split("."),i=e[0].length,u=r[0].length;return i>u?r[0]=new Array(Math.abs(i-u)+1).join("0")+(r[0]?r[0]:""):e[0]=new Array(Math.abs(i-u)+1).join("0")+(e[0]?e[0]:""),i=e[1]?e[1].length:0,u=r[1]?r[1].length:0,(i||u)&&(i>u?r[1]=(r[1]?r[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]:""),n=r[0]+(r[1]?"."+r[1]:""),[t,n]}function a(t,n){a=o(t,n),t=a[0],n=a[1];for(var e="",r=0,i=t.length-1;i>=0;i--)if("."!==t[i]){var u=parseInt(t[i])+parseInt(n[i])+r;e=u%10+e,r=Math.floor(u/10)}else e="."+e;return r?r.toString()+e:e;var a}Object.defineProperty(n,"__esModule",{value:!0}),n.add=r,n.trim=u,n.pad=o},function(t,n,e){"use strict";function r(t,n,e){if(void 0===n&&(n=0),void 0===e&&(e=o.RoundingModes.HALF_EVEN),e===o.RoundingModes.UNNECESSARY)throw new Error("UNNECESSARY Rounding Mode has not yet been implemented");"number"==typeof t&&(t=t.toString());var a=!1;"-"===t[0]&&(a=!0,t=t.substring(1));var s=t.split("."),l=s[0],d=s[1];if(n<0){if(n=-n,l.length<=n)return"0";var f=l.substr(0,l.length-n);return t=f+"."+l.substr(l.length-n)+d,f=r(t,0,e),(a?"-":"")+f+new Array(n+1).join("0")}if(0==n){l.length;return i(s[1],l,a,e)?(a?"-":"")+u(l):(a?"-":"")+l}if(!s[1])return(a?"-":"")+l+"."+new Array(n+1).join("0");if(s[1].length<n)return(a?"-":"")+l+"."+s[1]+new Array(n-s[1].length+1).join("0");d=s[1].substring(0,n);var g=s[1].substring(n);return g&&i(g,d,a,e)&&(d=u(d),d.length>n)?u(l,parseInt(d[0]))+"."+d.substring(1):(a?"-":"")+l+"."+d}function i(t,n,e,r){if(!t||t===new Array(t.length+1).join("0"))return!1;if(r===o.RoundingModes.DOWN||!e&&r===o.RoundingModes.FLOOR||e&&r===o.RoundingModes.CEILING)return!1;if(r===o.RoundingModes.UP||e&&r===o.RoundingModes.FLOOR||!e&&r===o.RoundingModes.CEILING)return!0;var i="5"+new Array(t.length).join("0");if(t>i)return!0;if(t<i)return!1;switch(r){case o.RoundingModes.HALF_DOWN:return!1;case o.RoundingModes.HALF_UP:return!0;case o.RoundingModes.HALF_EVEN:default:return parseInt(n[n.length-1])%2==1}}function u(t,n){void 0===n&&(n=0),n||(n=1),"number"==typeof t&&t.toString();for(var e=t.length-1,r="",i=e;i>=0;i--){var u=parseInt(t[i])+n;10==u?(n=1,u=0):n=0,r+=u}return n&&(r+=n),r.split("").reverse().join("")}Object.defineProperty(n,"__esModule",{value:!0});var o=e(2);n.roundOff=r},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});!function(t){t[t.CEILING=0]="CEILING",t[t.DOWN=1]="DOWN",t[t.FLOOR=2]="FLOOR",t[t.HALF_DOWN=3]="HALF_DOWN",t[t.HALF_EVEN=4]="HALF_EVEN",t[t.HALF_UP=5]="HALF_UP",t[t.UNNECESSARY=6]="UNNECESSARY",t[t.UP=7]="UP"}(n.RoundingModes||(n.RoundingModes={}))},function(t,n,e){"use strict";var r=e(0),i=e(1),u=e(4),o=e(5),a=e(6),s=e(7),l=e(2),d=function(){function t(n){void 0===n&&(n="0"),this.value=t.validate(n)}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 n=t.split(/[eE]/),e=n[0],i=n[1];e=r.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?r.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(n,e,r){if(e||r){if(!e||!r)throw Error("Illegal Arguments. Should pass both digits and separator or pass none")}else e=3,r=",";n=t.validate(n);var i="-"==n.charAt(0);i&&(n=n.substring(1));var u=n.indexOf(".");u=u>0?u:n.length;for(var o="",a=u;a>0;)a<e?(e=a,a=0):a-=e,o=n.substring(a,a+e)+(a<u-e&&a>=0?r:"")+o;return(i?"-":"")+o+n.substring(u)},t.prototype.getPrettyValue=function(n,e){return t.getPrettyValue(this.value,n,e)},t.round=function(n,e,r){if(void 0===e&&(e=0),void 0===r&&(r=l.RoundingModes.HALF_EVEN),n=t.validate(n),isNaN(e))throw Error("Precision is not a number: "+e);return i.roundOff(n,e,r)},t.prototype.round=function(n,e){if(void 0===n&&(n=0),void 0===e&&(e=l.RoundingModes.HALF_EVEN),isNaN(n))throw Error("Precision is not a number: "+n);return new t(i.roundOff(this.value,n,e))},t.floor=function(n){return n=t.validate(n),-1===n.indexOf(".")?n:t.round(t.subtract(n,.5))},t.prototype.floor=function(){return-1===this.value.indexOf(".")?new t(this.value):this.subtract(new t(.5)).round()},t.ceil=function(n){return n=t.validate(n),-1===n.indexOf(".")?n:t.round(t.add(n,.5))},t.prototype.ceil=function(){return-1===this.value.indexOf(".")?new t(this.value):this.add(new t(.5)).round()},t.add=function(n,e){return n=t.validate(n),e=t.validate(e),r.add(n,e)},t.prototype.add=function(n){return new t(r.add(this.value,n.getValue()))},t.subtract=function(n,e){return n=t.validate(n),e=t.validate(e),s.subtract(n,e)},t.prototype.subtract=function(n){return new t(s.subtract(this.value,n.getValue()))},t.multiply=function(n,e){return n=t.validate(n),e=t.validate(e),u.multiply(n,e)},t.prototype.multiply=function(n){return new t(u.multiply(this.value,n.getValue()))},t.divide=function(n,e,r){return n=t.validate(n),e=t.validate(e),o.divide(n,e,r)},t.prototype.divide=function(n,e){return new t(o.divide(this.value,n.getValue(),e))},t.compareTo=function(n,e){return n=t.validate(n),e=t.validate(e),a.compareTo(n,e)},t.prototype.compareTo=function(t){return a.compareTo(this.value,t.getValue())},t.negate=function(n){return n=t.validate(n),s.negate(n)},t.prototype.negate=function(){return new t(s.negate(this.value))},t.RoundingModes=l.RoundingModes,t}();t.exports=d},function(t,n,e){"use strict";function r(t,n){t=t.toString(),n=n.toString();var e=0;"-"==t[0]&&(e++,t=t.substr(1)),"-"==n[0]&&(e++,n=n.substr(1)),t=u(t),n=u(n);var r=0,o=0;-1!=t.indexOf(".")&&(r=t.length-t.indexOf(".")-1),-1!=n.indexOf(".")&&(o=n.length-n.indexOf(".")-1);var a=r+o;if(t=u(t.replace(".","")),n=u(n.replace(".","")),t.length<n.length){var s=t;t=n,n=s}if("0"==n)return"0";for(var l=n.length,d=0,f=[],g=l-1,c="",v=0;v<l;v++)f[v]=t.length-1;for(var v=0;v<2*t.length;v++){for(var h=0,p=n.length-1;p>=g&&p>=0;p--)f[p]>-1&&f[p]<t.length&&(h+=parseInt(t[f[p]--])*parseInt(n[p]));h+=d,d=Math.floor(h/10),c=h%10+c,g--}return c=u(i(c,a)),1==e&&(c="-"+c),c}function i(t,n){return 0==n?t:(t=n>=t.length?new Array(n-t.length+1).join("0")+t:t,t.substr(0,t.length-n)+"."+t.substr(t.length-n,n))}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(n,"__esModule",{value:!0}),n.multiply=r},function(t,n,e){"use strict";function r(t,n,e){if(void 0===e&&(e=8),0==n)throw new Error("Cannot divide by 0");if(t=t.toString(),n=n.toString(),0==t)return"0";var r=0;"-"==n[0]&&(n=n.substring(1),r++),"-"==t[0]&&(t=t.substring(1),r++);var o=n.indexOf(".")>0?n.length-n.indexOf(".")-1:-1;if(n=i.trim(n.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,d=n.length,f="",g=t.indexOf(".")>-1&&t.indexOf(".")<d?t.substring(0,d+1):t.substring(0,d);if(t=t.indexOf(".")>-1&&t.indexOf(".")<d?t.substring(d+1):t.substring(d),g.indexOf(".")>-1){var c=g.length-g.indexOf(".")-1;g=g.replace(".",""),d>g.length&&(c+=d-g.length,g+=new Array(d-g.length+1).join("0")),l=c,f="0."+new Array(c).join("0")}for(e+=2;l<=e;){for(var v=0;parseInt(g)>=parseInt(n);)g=i.add(g,"-"+n),v++;f+=v,t?("."==t[0]&&(f+=".",l++,t=t.substring(1)),g+=t.substring(0,1),t=t.substring(1)):(l||(f+="."),l++,g+="0")}return(1==r?"-":"")+i.trim(u.roundOff(f,e-2))}Object.defineProperty(n,"__esModule",{value:!0});var i=e(0),u=e(1);n.divide=r},function(t,n,e){"use strict";function r(t,n){var e=!1;if("-"==t[0]&&"-"!=n[0])return-1;if("-"!=t[0]&&"-"==n[0])return 1;if("-"==t[0]&&"-"==n[0]&&(t=t.substr(1),n=n.substr(1),e=!0),u=i.pad(t,n),t=u[0],n=u[1],0==t.localeCompare(n))return 0;for(var r=0;r<t.length;r++)if(t[r]!=n[r])return t[r]>n[r]?e?-1:1:e?1:-1;return 0;var u}Object.defineProperty(n,"__esModule",{value:!0});var i=e(0);n.compareTo=r},function(t,n,e){"use strict";function r(t,n){return t=t.toString(),n=n.toString(),n=i(n),u.add(t,n)}function i(t){return t="-"==t[0]?t.substr(1):"-"+t}Object.defineProperty(n,"__esModule",{value:!0});var u=e(0);n.subtract=r,n.negate=i}]);
{
"name": "js-big-decimal",
"version": "1.1.8",
"version": "1.2.0",
"description": "Work with large numbers on the client side. Round them off to any required precission.",

@@ -5,0 +5,0 @@ "main": "dist/node/js-big-decimal",

@@ -93,4 +93,4 @@ # JS Big Decimal

### round(number, precision)
Returns the rounded value to the specified precision (number of digits after decimal). The default is set to 0 if no argument is passed.
### round(number, precision, roundingMode)
Returns the rounded value to the specified precision (number of digits after decimal). The default precision is set to 0 and rounding mode set to `HALF_EVEN` if no argument is passed.
```javascript

@@ -111,2 +111,20 @@ var value = bigDecimal.round("123.678", 2); // value = "123.68"

Round also supports the following rounding modes (These are same as that of Java 8):
* `CEILING` - Rounding mode to round towards positive infinity.
* `DOWN` - Rounding mode to round towards zero.
* `FLOOR` - Rounding mode to round towards negative infinity.
* `HALF_DOWN` - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
* `HALF_EVEN` - Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
* `HALF_UP` - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
* `UNNECESSARY` (!Not Implemented!)- Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
* `UP` - Rounding mode to round away from zero.
Extensive description of the modes can be found at [Rounding Modes](https://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html)
```javascript
var num = new bigDecimal("123.657");
var numRound1 = num.round(1, bigDecimal.RoundingModes.DOWN); // "123.6"
var numRound2 = num.round(2, bigDecimal.RoundingModes.CEILING); // "123.66"
```
### floor(number)

@@ -113,0 +131,0 @@ Returns the whole number nearest but not greater than the input number.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc