import{isE as f,num2str as d,validateNumber as b,trimNumber as c,getNumberPrecision as N}from"./numberUtil.mjs";import{supportBigInt as E}from"./supportUtil.mjs";function l(i){return!i&&i!==0&&!Number.isNaN(i)||!String(i).trim()}class s{origin="";number;empty;constructor(t){if(l(t)){this.empty=!0;return}this.origin=String(t),this.number=Number(t)}negate(){return new s(-this.toNumber())}add(t){if(this.isInvalidate())return new s(t);const e=Number(t);if(Number.isNaN(e))return this;const r=this.number+e;if(r>Number.MAX_SAFE_INTEGER)return new s(Number.MAX_SAFE_INTEGER);if(r<Number.MIN_SAFE_INTEGER)return new s(Number.MIN_SAFE_INTEGER);const n=Math.max(N(this.number),N(e));return new s(r.toFixed(n))}isEmpty(){return this.empty}isNaN(){return Number.isNaN(this.number)}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(t){return this.toNumber()===t?.toNumber()}lessEquals(t){return this.add(t.negate().toString()).toNumber()<=0}toNumber(){return this.number}toString(t=!0){return t?this.isInvalidate()?"":d(this.number):this.origin}}class m{origin="";negative;integer;decimal;decimalLen;empty;nan;constructor(t){if(l(t)){this.empty=!0;return}if(this.origin=String(t),t==="-"||Number.isNaN(t)){this.nan=!0;return}let e=t;if(f(e)&&(e=Number(e)),e=typeof e=="string"?e:d(e),b(e)){const r=c(e);this.negative=r.negative;const n=r.trimStr.split(".");this.integer=BigInt(n[0]);const a=n[1]||"0";this.decimal=BigInt(a),this.decimalLen=a.length}else this.nan=!0}getMark(){return this.negative?"-":""}getIntegerStr(){return this.integer.toString()}getDecimalStr(){return this.decimal.toString().padStart(this.decimalLen,"0")}alignDecimal(t){const e=`${this.getMark()}${this.getIntegerStr()}${this.getDecimalStr().padEnd(t,"0")}`;return BigInt(e)}negate(){const t=new m(this.toString());return t.negative=!t.negative,t}add(t){if(this.isInvalidate())return new m(t);const e=new m(t);if(e.isInvalidate())return this;const r=Math.max(this.getDecimalStr().length,e.getDecimalStr().length),n=this.alignDecimal(r),a=e.alignDecimal(r),g=(n+a).toString(),{negativeStr:h,trimStr:u}=c(g),o=`${h}${u.padStart(r+1,"0")}`;return new m(`${o.slice(0,-r)}.${o.slice(-r)}`)}isEmpty(){return this.empty}isNaN(){return this.nan}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(t){return this.toString()===t?.toString()}lessEquals(t){return this.add(t.negate().toString()).toNumber()<=0}toNumber(){return this.isNaN()?Number.NaN:Number(this.toString())}toString(t=!0){return t?this.isInvalidate()?"":c(`${this.getMark()}${this.getIntegerStr()}.${this.getDecimalStr()}`).fullStr:this.origin}}function $(i){return E()?new m(i):new s(i)}function I(i,t,e,r=!1){if(i==="")return"";const{negativeStr:n,integerStr:a,decimalStr:g}=c(i),h=`${t}${g}`,u=`${n}${a}`;if(e>=0){const o=Number(g[e]);if(o>=5&&!r){const S=$(i).add(`${n}0.${"0".repeat(e)}${10-o}`);return I(S.toString(),t,e,r)}return e===0?u:`${u}${t}${g.padEnd(e,"0").slice(0,e)}`}return h===".0"?u:`${u}${h}`}export{m as BigIntDecimal,s as NumberDecimal,$ as default,I as toFixed};
