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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vicnaum/bigdecimal

v0.1.7

Published

BigDecimal library based on BigNumber from ethers.js.

Downloads

5

Readme

BigDecimal

This library was made to simplify the Web3 development by extending BigNumber package from ethers.js with Decimals property and overriding the corresponding math.

Put simply - now you don't need parseEthers, formatEthers, and convert numbers/strings/bignumbers to each other.

BigDecimal structure/features:

  1. inheriting BigNumber - so you don't need to change anything in your code - and can pass BigDecimal wherever you had BigNumber before
  2. BigDecimal.decimals property - stores how many decimals this number has. Default is 18
  3. BigDecimal.value property - stores the numeric value of the bignumber with decimals applied - for human-readable display and use anywhere where you would use a simple number

Usage

You can look in the test folder for all possible use-cases of BigDecimal.

And the source code src.ts/BigDecimal.ts also has very verbose comments on usage.

For now it only supports multiplication, division, addition and subtraction.

// You can create BigDecimal with Number, with string, or with BigNumber.
// You can pass the number of decimals as the second argument. If nothing is passed - default is assumed to be 18

// When creating BigDecimal from a number - it is converted to 18 decimals and stored as a BigNumber with 18 zeroes
const fiveEthers = new BigDecimal(5) // Same as BigNumber.from(5 with 18 zeroes) or parseEther(5)

// When creating with a BigNumber - it's assumed that decimals are already included:
const hundredUSDC = new BigDecimal(BigNumber.from("100000000"), 6) // Same as parseUnits(100, 6)

// When creating with a string - there are two ways:
// 1) same as BigNumber, where the decimals are assumed to be included:
const hundredUSDC = new BigDecimal("100000000", 6) // Same as parseUnits(100, 6)

// 1) set parseString to true - then the string will be parsed and treated as a number:
const hundredUSDC = new BigDecimal("100", 6, true) // Same as parseUnits("100", 6)

const meaning = new BigDecimal(BigNumber.from(42), 0) // 42 with 0 decimals

const half = hundredUSDC.mul(0.5) // equals hundredUSDC * 0.5 = 50 USDC with 6 decimals

const fivePercent = new Bigdecimal(0.05) // equals 0.05 * 1e18

const multiplication = hundredUSDC.mul(fivePercent) // equals 5 USDC with 6 decimals

const division = hundredUSDC.div(half) // equals 200 USDC with 6 decimals

console.log(hundredUSDC) // outputs 100 - human readable number with decimals applied to it

hundredUSDC.decimals // equals 6

License

MIT License