UNPKG

@abaplint/runtime

Version:
72 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Packed = void 0; const float_1 = require("./float"); const throw_error_1 = require("../throw_error"); const integer8_1 = require("./integer8"); const digits = new RegExp(/^\s*-?\+?\d*\.?\d* *$/i); class Packed { constructor(input) { this.value = 0; this.length = 666; if (input?.length) { this.length = input.length; } this.decimals = 0; if (input?.decimals) { this.decimals = input.decimals; } this.qualifiedName = input?.qualifiedName; } clone() { const n = new Packed({ length: this.length, decimals: this.decimals, qualifiedName: this.qualifiedName }); n.value = this.value; return n; } getQualifiedName() { return this.qualifiedName; } round(value, places) { // @ts-ignore return +(Math.round(value + "e+" + places) + "e-" + places); } set(value) { if (typeof value === "number") { this.value = value; } else if (typeof value === "string") { if (value.trim().length === 0) { this.value = 0; return this; } else if (digits.test(value) === false) { (0, throw_error_1.throwError)("CX_SY_CONVERSION_NO_NUMBER"); } this.value = this.round(parseFloat(value), this.decimals); } else if (value instanceof integer8_1.Integer8) { this.value = Number(value.get()); } else if (value instanceof float_1.Float) { this.value = this.round(value.getRaw(), this.decimals); } else { this.set(value.get()); } return this; } getLength() { return this.length; } getDecimals() { return this.decimals; } clear() { this.value = 0; } get() { return this.value; } } exports.Packed = Packed; //# sourceMappingURL=packed.js.map