numeral-calc
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

numeral-calc

logo

Solve the ECMAScript language large number calculation and floating point number problem.

Supports scientific numeration calculations.

Build Status Coverage Status Version npm bundle size last-commit-date-logo

Installation

The numeral-calc package lives in npm. To install the latest stable version, run the following command:

npm i numeral-calc

Or if you're using yarn:

yarn add numeral-calc

Usage

Codepen Demo

import { add, sub, multi, divide, calc } from 'numeral-calc';

add(0.1,0.2) // "0.3"
In the same way: calc(0.1,0.2,"+")  //  "+" can be replaced by "and" or "plus" or "add"

add(0.1,0.2,1) // "1.3"

sub(0.3,0.1) // "0.2"
In the same way: calc(0.3,0.1,"-")  //  "-" can be replaced by "minus" or "sub" or "subtract"
/* Support for custom scientific notation. */
sub(1.02e1,1.3e-4)  //  "10.19987"

multi(1.15,100) // "115"

multi(1.15,100,2) // "230"
In the same way: calc(1.15,100,"*")   //  "*" can be replaced by "x" or "multi" or "multiply"

divide(9007199254740997,2) // "4503599627370498.5"
In the same way: calc(9007199254740997,2,"/")   //  "/" can be replaced by "divide"

Objective

Use the simplest method to solve the most fundamental problem.

  • No new types are generated.
  • Floating-point and large numbers are handled together using numeral-calc.

The underlying method relies on the BigInt data type.

Addition and multiplication can take multiple arguments.

Notice

There seems to be no such business scenario.

  • The divisor cannot exceed the safe range of the JS language.
  • Scientific notation exponentials cannot exceed the safe limits of the JS language.

Package Sidebar

Install

npm i numeral-calc

Weekly Downloads

48

Version

1.0.9

License

ISC

Unpacked Size

36.5 kB

Total Files

14

Last publish

Collaborators

  • galenyoung