strnumber
v1.1.2
Published
This is a numerical calculation class, which is used to solve the problem of precision loss of js floating point number operation and large number operation. It encapsulates the common addition, subtraction, multiplication and division calculation methods
Maintainers
Readme
StrNumber
This is a numerical calculation class, which is used to solve the problem of precision loss of js floating point number operation and large number operation. It encapsulates the common addition, subtraction, multiplication and division calculation methods, including toFixed, trunk methods, etc. The instance supports chain call calculation methods, which can also be called in static methods. Type conversion is similar to the native numeric class - Number.
Installation
$ npm install strnumber
$ pnpm add strnumberExample
import { StrNumber, strNumber } from 'strnumber'
const a = new StrNumber(1) // or strNumber(1)
// Support chain calls and multiple parameter types
const b = a.add(1, '1e+17').times(new StrNumber(2)) // new StrNumber('200000000000000004')
// Support calling static methods
const c = StrNumber.add(1, 2) // '3'
// Support formula calculation
const c = StrNumber.calc(`(1+${b})*4`) // '800000000000000020'
// Support implicit type conversion
const d = a + 2 // 3