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

cyou-big-number

v1.0.6

Published

see-you-big-number

Downloads

13

Readme

cyou-big-number

Travis (.com) Codecov NPM npm npm npm bundle size GitHub last commit

Simple decimal arithmetic for the browser and node.js

This package is based on decimal.js-light and offer some very simple API for big decimal.

  • {number | string} transform to decimal
  • {decimal} to fixed format
  • decimal arithmetic add/subtract/multiply/divide

Now, see you big number.

Installation

$ npm install cyou-big-number --save

Usage

In the Browser

<script src="dist/umd/index.umd.js"></script>

In node

import {numberToString, decimalToString, decimalPlus, decimalMinus, decimalTimes, decimalDiv} from 'cyou-big-number'

Examples

// Supports at least 20 integers to 10 decimals
numberToString('123456789012345678790.12345678901234567890'); // '123456789012345678790.123456789'
numberToString('9e-10'); // '0.0000000009'
numberToString(9e-10); // '0.0000000009'

// helpful format
numberToString('1.12345000000000'); // '1.12345'
numberToString('1.12345000000000', {minFixed: 10}); // '1.1234500000'
numberToString('1.12345000000000', {maxFixed: 2}); // '1.12'

// No loss of accuracy
decimalToString(decimalPlus(0.1, 0.2)); // '0.30'

decimalToString(decimalMinus(5, 1, 1, 1, 1, 1)); // '0.00'

numberToString(
    decimalTimes(Number.MAX_SAFE_INTEGER, 1000)
); // '9007199254740991000'

numberToString(
  decimalDiv(1000, 1000, 1000, 1000)
); // '0.000001'

API

numberToDecimalObj

src/index.js:9-17

Parameters

  • number

Returns Decimal

n2d

src/index.js:24-24

Type: numberToDecimalObj

decimalToString

src/index.js:38-45

transform String/Number/Decimal to a fixed format 1. minFixed <= decimal part length <= maxFixed 2. decimal part will no keep 0 at the tail, unless decimal part length is small than minFixed

Parameters

  • number (string | number | Decimal)
  • $1 Object (optional, default {})
    • $1.minFixed (optional, default 2)
    • $1.maxFixed (optional, default 10)
  • minFixed default to be 2, it means 1.0 will be transformed to 1.00, but 1.000 will not be effected this param will keep 0 at the tail of number
  • maxFixed default to be 10, it means Math.fixed(10) and this param will no keep 0 at the tail of number, it means 1.11000 will transform to 1.11, bug 1.11111 will not be effected

Returns (string | string) number in format

d2s

src/index.js:52-52

This function is alias for decimalToString

Returns string number in string format

numberToString

src/index.js:59-59

This function is alias for decimalToString, just lik d2s

Returns string number in string format

n2s

src/index.js:66-66

This function is alias for numberToString

Returns string number in string format

decimalPlus

src/index.js:75-77

this function receive multiple addends and return the sum in a Decimal Object

Parameters

Returns Decimal sum

decimalPlusToString

src/index.js:86-88

This function is similar as decimalPlus, bug return the sum in a string

Parameters

Returns string sum

decimalMinus

src/index.js:97-99

this function receive one minuend and multiple subtrahend and return the subtract output in a Decimal Object

Parameters

  • num1 (string | number | Decimal) first number is minuend, is required
  • nums (string | number | Decimal) the other subtrahend

Returns Decimal minuend

decimalMinusToString

src/index.js:108-110

This function is similar as decimalMinus, bug return the minuend in a string

Parameters

Returns string minuend

decimalTimes

src/index.js:119-121

this function receive one multiplicand and multiple multiplier, return the product in a Decimal Object

Parameters

  • num1 (string | number | Decimal) first number is multiplicand, is required
  • nums (string | number | Decimal) the other multiplier

Returns Decimal the product in a Decimal Object

decimalTimesToString

src/index.js:130-132

This function is similar as decimalTimes, bug return the product in a string

Parameters

Returns string product

decimalDiv

src/index.js:141-143

this function receive one dividend and multiple divisor, return the product in a Decimal Object

Parameters

  • num1 (string | number | Decimal) first number is dividend, is required
  • nums (string | number | Decimal) the other divisor

Returns Decimal the dividend in a Decimal Object

decimalDivToString

src/index.js:152-154

This function is similar as decimalDiv, bug return the dividend in a string

Parameters

Returns string dividend

Related

TODOS

  • Enables functions to support chain calls
  • add prettier budge

License

This project is licensed under the MIT license.