npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

big-calculator

v1.0.0

Published

big-calculator 是基于 ES2020 新增的基础数据类型 BigInt 及 [decimal.js](https://github.com/MikeMcl/decimal.js) 进行超大整数/小数计算简单工具函数。 ---

Downloads

2

Readme

big-calculator

big-calculator 是基于 ES2020 新增的基础数据类型 BigInt 及 decimal.js 进行超大整数/小数计算简单工具函数。

安装

npm install big-calculator --save
# or
yarn add big-calculator

使用

// 全量引用
import calculator, { add, sub, mul, div, compare, calc } from "../src/index";
// 加
const addNum = calculator.add("123.788", "78345.22123458");
// -> 78469.00923458
// 减
const subNum = calculator.sub("4354.3", "0.14498832");
// -> 4354.15501168
// 乘
const mulNum = calculator.mul("253365.458", "778552.7852");
// -> 197258382999.37362160
// 除
const divNum = calculator.div("0.72045456", "3564566154345");
// -> 2.0211563730464296
# or
// 按需引用
import { add, sub, mul, div } from "big-calculator";

const addNum = add("1115321211.9982054", "1398415615111.28");
// -> 1399530936323.2782054
const subNum = sub("1.3", "0.1");
// -> 1.2
const mulNum = mul("99984412349.222", "99989419.4566");
// -> 9997383345508015560.67276520
const divNum = div("0.45565213424511", "0.12121341234234");
// -> 3.7590900663552240

精度

加减乘除默认精度为有效数,最大精度为16

const addNum = add("1115321211.9982054", "1398415615111.28", 6);
// -> 1399530936323.278205
const subNum = sub("1.3", "0.1",4);
// -> 1.2

比较

const isResult_1 = compare("123123.999", "123123.999", "===")
// -> true
const isResult_2 = compare("123123.999", "123123.999", "<")
// -> false
const isResult_3 = compare("123123.999", "123123.999", ">")
// -> false
const isResult_4 = compare("123123.999", "123123.999", "<=")
// -> true
const isResult_5 = compare("123123.999", "123123.999", ">=")
// -> true

字符串模板计算

const calc_1 = calc("123123.999 + 123123.999")
// -> 246247.998
const calc_2 = calc("123123.999 + 123123.999 - -25451.34 * 5415418.44 / 96342")
// -> 1676876.9652075481098586