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

@finam/decimal

v1.2.0

Published

Precise decimal arithmetic on BigInt

Readme

@finam/decimal

Библиотека для точной арифметики с десятичными дробями на основе BigInt. Позволяет работать с денежными суммами, курсами и другими числами, где недопустима потеря точности при округлении number.

Установка

npm install @finam/decimal

Создание экземпляра

import { Decimal } from '@finam/decimal';

// Из строки (целое, дробное, научная нотация)
Decimal.fromString('123.456');    // Decimal(123456, 3)
Decimal.fromString('1.5e5');     // Decimal(150000, 0)
Decimal.fromString('1e-10');     // Decimal(1, 10)

// Из числа
Decimal.fromNumber(1.5);         // Decimal(15, 1)

// Из bigint + scale
new Decimal(BigInt(12345), 2);  // Decimal(12345, 2) → "123.45"

// Универсальный метод
Decimal.fromAny('1.5');          // строка
Decimal.fromAny(BigInt(100));    // bigint
Decimal.fromAny(3.14);           // number
Decimal.fromAny(someDecimal);    // Decimal

// Константа
Decimal.ZERO;                    // 0

Арифметические операции

const a = Decimal.fromString('1.5');
const b = Decimal.fromString('2.3');

a.plus(b);    // 3.8
a.minus(b);   // -0.8
a.mul(b);     // 3.45
a.div(b);     // 0.652173913043478 (precision по умолчанию 15)
a.div(b, 5);  // 0.65217
a.pow(3);     // 3.375
a.round();    // 2

pow принимает целую неотрицательную степень.

round округляет до заданного числа знаков после запятой по правилу half-up - отличается от Math.round, который округляет середину всегда в сторону +Infinity:

Сравнение

const x = Decimal.fromString('1.5');
const y = Decimal.fromString('2.0');

x.compare(y); // -1
x.eq(y);      // false
x.gt(y);      // false
x.lt(y);      // true
x.gte(y);     // false
x.lte(y);     // true

Проверки и преобразования

const d = Decimal.fromString('0.05');

d.isZero();      // false
d.isPositive();  // true
d.isNegative();  // false

d.toString();    // "0.05"
d.toNumber();    // 0.05
d.clone();       // новый экземпляр Decimal

d.unscaledValue; // BigInt(5)
d.scale;         // 2

Особенности

  • Операции выполняются через BigInt — нет потери точности для любых значений
  • Автоматическое удаление конечных нулей при создании (123.1000123.1)
  • Поддержка научной нотации при парсинге (1.5e10, 1e-5)
  • Настраиваемая точность деления (по умолчанию 15 знаков)
  • Числа больше Number.MAX_SAFE_INTEGER обрабатываются без потери точности