@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.9 to 1.0.0-rc.10
@@ -104,2 +104,3 @@ import { Chain } from '@swapkit/types'; | ||
toSignificant(significantDigits?: number): string; | ||
toFixed(fixedDigits?: number): string; | ||
} | ||
@@ -106,0 +107,0 @@ |
@@ -778,2 +778,12 @@ var _t = Object.defineProperty; | ||
} | ||
toFixed(t = 6) { | ||
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || ""; | ||
if (parseInt(n)) | ||
return `${n}.${i.slice(0, t)}`.padEnd(t, "0"); | ||
const a = parseInt(i), c = `${a}`.slice(0, t); | ||
return `0.${c.padStart( | ||
i.length - `${a}`.length + c.length, | ||
"0" | ||
)}`; | ||
} | ||
}; | ||
@@ -780,0 +790,0 @@ w = new WeakSet(), v = function(t, ...e) { |
@@ -45,3 +45,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.9", | ||
"version": "1.0.0-rc.10", | ||
"scripts": { | ||
@@ -48,0 +48,0 @@ "build": "vite build", |
@@ -255,2 +255,20 @@ import { BaseDecimal } from '@swapkit/types'; | ||
toFixed(fixedDigits: number = 6) { | ||
const [int, dec] = this.getValue('string').split('.'); | ||
const integer = int || ''; | ||
const decimal = dec || ''; | ||
if (parseInt(integer)) { | ||
return `${integer}.${decimal.slice(0, fixedDigits)}`.padEnd(fixedDigits, '0'); | ||
} | ||
const trimmedDecimal = parseInt(decimal); | ||
const slicedDecimal = `${trimmedDecimal}`.slice(0, fixedDigits); | ||
return `0.${slicedDecimal.padStart( | ||
decimal.length - `${trimmedDecimal}`.length + slicedDecimal.length, | ||
'0', | ||
)}`; | ||
} | ||
#arithmetics(method: 'add' | 'sub' | 'mul' | 'div', ...args: InitialisationValueType[]): this { | ||
@@ -257,0 +275,0 @@ const precisionDecimal = this.#retrievePrecisionDecimal(this, ...args); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
188102
3473