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

bigint-precision

v1.3.0

Published

This is to ensure precision on decimals for BigInt maths.

Downloads

1

Readme

bigint-precision

This is to ensure precision on decimals for BigInt maths.

Installation

  npm install bigint-precision

How to construct a BIP class.

Instead of using the new constructor, we favour using the .from()

From takes 2 arguments, the value and the exponent.

For example, the value of 3.141590 would be entered as below.

BIP.from(3_141590n, 6n)

We add _ as it's an easier visual cue to track it

fromNumber

.fromNumber can take a whole number, floating point or evemn scientific notation as an input and allow you to perform big maths on it.

BIP.fromNumber(20000)
BIP.fromNumber(20.12221)
BIP.fromNumber("1.2112222222222222e+22");

Return the value

To return the value after applying some maths, we have the following options.

  • unscale
  • toNumber
  • toString
  • toFormat

Unscale

unscale returns the bigint value to the precision dictated by the argument.

BIP.from(3_141590n, 6n).unscale(2n)

This will return 3_14n

toNumber

unscale returns a number data type and takes no arguments.

BIP.from(3_141590n, 6n).toNumber()

This will return 3.14159

toString

unscale returns a string data type and takes no arguments.

BIP.from(3_141590n, 6n).toString()

This will return "3.14159"

toFormat

unscale returns a string data type and returns a formated string.

The current type of formats are:

  • Euro
  • Dollar
  • CyptoToken
  • Percent

Please contact me if you want anymore formats added.

BIP.from(1000_36n, 2n).toFormat(BIP.FORMAT_EUR))

This will return "1.000,36"

Math operators

This includes the following elementary arithmetic operators.

  • Addition
  • Subtraction
  • Multiplication
  • Division

Addition

   const summands = BIP.from(2_0n, 1n);
    const sum = summands.add(BIP.from(1_14159n, 5n)).unscale(5n);

The sum will be 3_14159n

Subtraction

    const minuend = BIP.from(10_00n, 2n);
    const difference = minuend.sub(BIP.from(6_8584n, 4n)).unscale(4n);

The difference will return 3_146n

Multiplication

    const multiplicand = BIP.from(300_00000n, 5n);
    const product = multiplicand.mul(BIP.from(5n)).unscale(2n);

The product will be 3_146n

Division

    const dividend = BIP.from(233546921420225777694970883318153571_000n, 3n);
    const divisor = BIP.from(74340293968115785654927455866388593n, 0n);
    const quotient = dividend.div(divisor).unscale(18n);

The quotient will be 3_141592653916501746n