UNPKG

@cainiaofe/cn-utils

Version:

菜鸟前端基础工具库

75 lines (74 loc) 2.91 kB
import { __assign } from "tslib"; import BigNumber from 'bignumber.js'; import { getNumSysFormatConf } from './i18n'; import { getLang } from '../common/utils'; var I18nNumber = /** @class */ (function () { function I18nNumber(value, lang) { this.value = new BigNumber(value); this.lang = getLang(lang); this.numSysFormatConf = getNumSysFormatConf(this.lang); this.ROUND_UP = BigNumber.ROUND_UP; this.ROUND_DOWN = BigNumber.ROUND_DOWN; this.ROUND_CEIL = BigNumber.ROUND_CEIL; this.ROUND_FLOOR = BigNumber.ROUND_FLOOR; this.ROUND_HALF_UP = BigNumber.ROUND_HALF_UP; this.ROUND_HALF_DOWN = BigNumber.ROUND_HALF_DOWN; this.ROUND_HALF_EVEN = BigNumber.ROUND_HALF_EVEN; this.ROUND_HALF_CEIL = BigNumber.ROUND_HALF_CEIL; this.ROUND_HALF_FLOOR = BigNumber.ROUND_HALF_FLOOR; } I18nNumber.prototype.getValue = function () { return this.value; }; // 获取当前值 I18nNumber.prototype.toFixed = function (decimalPlaces, roundingMode) { this.value = new BigNumber(this.value.toFixed(decimalPlaces, roundingMode)); return this; }; I18nNumber.prototype.toFormat = function (decimalPlaces, roundingMode, fmt) { return this.value.toFormat(decimalPlaces, roundingMode, __assign(__assign({}, this.numSysFormatConf), (fmt || {}))); }; I18nNumber.prototype.toNumber = function () { return this.value.toNumber(); }; I18nNumber.prototype.toPrecision = function (significantDigits, roundingMode) { this.value = new BigNumber(this.value.toPrecision(significantDigits, roundingMode)); return this; }; I18nNumber.prototype.comparedTo = function (n, base) { return this.value.comparedTo(n, base); }; I18nNumber.prototype.abs = function () { this.value = this.value.abs(); return this; }; I18nNumber.prototype.plus = function (n, base) { this.value = this.value.plus(n, base); return this; }; I18nNumber.prototype.minus = function (n, base) { this.value = this.value.minus(n, base); return this; }; I18nNumber.prototype.times = function (n, base) { this.value = this.value.times(n, base); return this; }; I18nNumber.prototype.div = function (n, base) { this.value = this.value.div(n, base); return this; }; I18nNumber.prototype.mod = function (n, base) { this.value = this.value.mod(n, base); return this; }; I18nNumber.prototype.isValid = function () { return this.value.isNaN() === false && this.value.isFinite() === true; }; I18nNumber.isValid = function (value) { var bigNumber = new BigNumber(value); return bigNumber.isNaN() === false && bigNumber.isFinite() === true; }; return I18nNumber; }()); export { I18nNumber };