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

@waves/bignumber

v1.2.0

Published

Waves Library for work with Bignumber in javascript

Downloads

4,594

Readme

@waves/bignumber

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.

Load

The library is the single JavaScript file bignumber.umd.js (or minified, bignumber.umd.min.js).

Browser:

<script src='path/to/bignumber.js'></script>

Node.js:

$ npm install @waves/bignumber
const { BigNumber } = require('@waves/bignumber');

ES6 module:

import { BigNumber } from "@waves/bignumber"

AMD loader libraries such as requireJS:

require(['@waves/bignumber'], function(BigNumber) {
    // Use BigNumber here in local scope. No global BigNumber.
});

Use

let x = new BigNumber(123.4567);
let y = BigNumber('123456.7e-3');
let z = new BigNumber(x);
x.eq(y) && y.eq(z) && x.eq(z);      // true

To get the string value of a BigNumber use toString() or toFixed(). Using toFixed() prevents exponential notation being returned, no matter how large or small the value.

let x = new BigNumber('1111222233334444555566');
x.toString();                       // "1111222233334444555566"
x.toFixed();                        // "1111222233334444555566"
Clone

Клонирует объект

const some = new BigNumber(1);
const clone = some.clone();
Add

Выполняет сложение

const bigNum = new BigNumber('100');
const result = bigNum.add('50'); // with method toFixed '150'
Sub

Вычитание

const bigNum = new BigNumber('100');
const result = bigNum.sub('50'); // with method toFixed '50'
Mul

Умножение

const bigNum = new BigNumber('100');
const result = bigNum.mul(2); // with method toFixed '200'
Div

Деление

const bigNum = new BigNumber('100');
const result = bigNum.div(2); //  with method toFixed '50'
Pow

Возведение в степень

const bigNum = new BigNumber('100');
const result = bigNum.pow(2); // with method toFixed '10000'
Sqrt

Квадратный корень

const bigNum = new BigNumber('100');
const result = bigNum.sqrt(); // with method toFixed '10'
Abs

Модуль

const bigNum = new BigNumber('-100');
const result = bigNum.abs(); // with method toFixed 100
Mod

Остаток от деления

const bigNum = new BigNumber('100');
const result = bigNum.mod(10); // with method toFixed '0' 
RoundTo

Округляет. Принимает количество знаков после запятой после округлени и режим округления см тут: http://mikemcl.github.io/bignumber.js/#constructor-properties

const bigNum = new BigNumber('100');
const result = bigNum.roundTo(); //
Eq

Равенство

const bigNum = new BigNumber('100');
const result = bigNum.eq(100); // true
Lt

Меньше

const bigNum = new BigNumber('100');
const result = bigNum.lt(); //
Gt

Больше

const bigNum = new BigNumber('100');
const result = bigNum.gt(); //
Lte

Меньше или равно

const bigNum = new BigNumber('100');
const result = bigNum.lte(); //
Gte

Больше или равно

const bigNum = new BigNumber('100');
const result = bigNum.gte(); //
IsNaN

Проверяет на NaN

const bigNum = new BigNumber('100');
const result = bigNum.isNaN(); // false
IsFinite

Проверяет на Infinity (положительный и отрицательный)

const bigNum = new BigNumber('100');
const result = bigNum.isFinite(); //
IsZero

Проверяет на равенство нулю

const bigNum = new BigNumber('100');
const result = bigNum.isZero(); // false
IsPositive

Больше нуля

const bigNum = new BigNumber('100');
const result = bigNum.isPositive(); // true
IsNegative

Меньше нуля

const bigNum = new BigNumber('100');
const result = bigNum.isNegative(); // false
IsInt

Проверяет целое ли число

const bigNum = new BigNumber('100');
const result = bigNum.isInt(); //
GetDecimalsCount

Получаем количество занков после запятой у числа

const bigNum = new BigNumber('100');
const result = bigNum.getDecimalsCount(); // 0
IsEven

Четное

const bigNum = new BigNumber('100');
const result = bigNum.isEven(); // true
IsOdd

Не чётное

const bigNum = new BigNumber('100');
const result = bigNum.isOdd(); // false
ToBytes

Переводим число в байты со знаком (8 байт). Работает только с целыми числами.

const bigNum = new BigNumber('100');
const result = bigNum.toBytes();
ToFormat

Выводим число в строковом эквиваленте c с учётом настроек форматирования. Опционально принимает количество знаков округления, режим округления (как в roundTo) и настройки формата вывода.

const bigNum = new BigNumber('1000000.12312');
bigNum.toFormat(); // 1,000,000.12312 
bigNum.toFormat(2); // 1,000,000.12 
bigNum.toFormat(2); // 1,000,000.12 
bigNum.toFormat(2, 0); // 1,000,000.13 
bigNum.toFormat(2, 0, { groupSeparator: ' ' }); // 1 000 000.13 
ToFixed

Выводим число в строковом эквиваленте. Опционально принимает количество знаков округления и режим округления (как в roundTo)

const bigNum = new BigNumber('100');
const result = bigNum.toFixed(); //
ToNumber

Приводит к числу

const bigNum = new BigNumber('100');
const result = bigNum.toNumber(); //

Static Methods

fromBytes

Выводит знаковое число из байт. Работает только с 8 байтами.

const some = BigNumber.fromBytes(Uint8Array.from([1,2,3,4,5,6,7,8]));
max

Принимает любое количество аргументов, выбирает наибольшее число из аргументов

BigNumber.max(1, '2', new BigNumber(4)); // with method toFixed '4'
min

Принимает любое количество аргументов, выбирает наименьшее число из аргументов

BigNumber.min(1, '2', new BigNumber(4)); // with method toFixed '1'
sum

Принимает любое количество аргументов, складывает числа

BigNumber.min(1, '2', new BigNumber(4)); //with method toFixed '7'