UNPKG

@cashfarm/lang

Version:

Extends TypeScript/Javascript with basic classes and functions

29 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const fqn_1 = require("./fqn"); const primitiveWrappers_1 = require("./primitiveWrappers"); let Decimal = class Decimal extends primitiveWrappers_1.NumberWrapper { constructor(value, precision = 2) { if (typeof value === 'string') { value = parseFloat(value); } if (typeof value !== 'number' || isNaN(value)) { throw new Error('Decimal constructor requires a number or the string representation of a number.'); } super(parseFloat((value ? value : 0).toFixed(precision))); this.precision = precision; } get primitiveValue() { return parseFloat(this.toFixed(this.precision)); } toString() { return this.toFixed(this.precision); } }; Decimal = tslib_1.__decorate([ fqn_1.FQN('@cashfarm/lang:Decimal'), tslib_1.__metadata("design:paramtypes", [Object, Number]) ], Decimal); exports.Decimal = Decimal; //# sourceMappingURL=decimal.js.map