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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fox-js/big-decimal

v4.0.1

Published

Fox Big Decimal utils

Readme

Fox Big Decimal

大数操作(加、减、乘、除、格式化)的工具类.

Install

NPM

npm i @fox-js/big-decimal -S

YARN

yarn add @fox-js/big-decimal

使用指南

直接在代码中引入模块即可,模块会自动完成初始化并生效

import '@fox-js/big-decimal'

乘

multiply(x, y)

import { multiply } from '@fox-js/big-decimal'
// 相乘
let n = multiply(336662, 3)
console.info(`multiply:${n}`)

除

divide(x, y, precision = 8)

import { divide } from '@fox-js/big-decimal'
// 相除(最后一位为小数点)
n = divide(36223, 3, 2)
console.info(`divide:${n}`)

加

add(x, y)

import { divide } from '@fox-js/big-decimal'
// 相加
n = add(3533, 15)
console.info(`add:${n}`)

减

subtract(x, y)

import { subtract } from '@fox-js/big-decimal'
// 相减
n = subtract(122223, 22321312)
console.info(`subtract:${n}`)

四舍五入

round(number, precision, roundingMode) 按指定的位数对数值进行四舍五入

import { round } from '@fox-js/big-decimal'

round('123.678', 2) //"123.68"
round('123.657', 1, RoundingModes.DOWN) // "123.6"
round('123.657', 2, RoundingModes.CEILING) // "123.66"

RoundingMode

Round also supports the following rounding modes

  • CEILING - Rounding mode to round towards positive infinity.
  • DOWN - Rounding mode to round towards zero.
  • FLOOR - Rounding mode to round towards negative infinity.
  • HALF_DOWN - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
  • HALF_EVEN - Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
  • HALF_UP - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
  • UNNECESSARY (!Not Implemented!)- Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
  • UP - Rounding mode to round away from zero.

floor

floor(number) Returns the whole number nearest but not greater than the input number.

floor(12.8) // "12"
floor(-12.3) // "-13"

ceil

ceil(number) Returns the whole number nearest but not lesser than the input number.

ceil(12.8) // "13"
ceil(-12.3) // "-12"

negate

Returns negation of a given number.

negate('123.678') //  "-123.678"
negate('-1234') //  "1234"

对比

numCompareTo(number1, number2) 比较两个数据,Returns 1, 0 and -1 if number1 > number2, number1 == number2 and number1 < number2 respectively.

compareTo('23.678', '67.34') // value = -1
compareTo('23.678', '23.6780') // value = 0
compareTo('123.678', '67.34') // value = 1

判断数字是否在范围内

inScope(number, min, max)

inScope('1', '1', '5') // false
inScope('3', '1', '10') // true

对数字进行扩展

scaleNumber(value, scale) 如果 scale>0 代表 multiply(value,scale) 如果 scale<0 代表 divide(value, negate(scale))

scaleNumber('100', '5') // 500
scaleNumber('100', '-5') // 20

数据格式化

numberFormat(value, decimalLength = -1, autoPadding = false, digits = 3, separator = ',')

  • value 待格式化 value
  • decimalLength(小数长度)
  • autoPadding(是否自动填充 0)
  • digits(分块长度)
  • separator(分块隔离符号)
numberFormat('123456') // 123,456
numberFormat('123456.978', 2) // 123,456.97
numberFormat('123456.9', 2, true) // 123,456.90

数据反格式化

unNumberFormat(value)

unNumberFormat('123,456') // 123456