Skip to main content

Built and signed on GitHub Actions

A library for working with arbitrary precision decimal numbers

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.1.8)

@quentinadam/decimal

JSR NPM CI

A library for working with arbitrary precision decimal numbers.

Decimal numbers are represented by a mantissa (bigint) and an exponent (number). Instances of the Decimal class are immutable; calling functions (like abs, add, ceil, ...) on an instance will return a new Decimal instance with the result. Division may fail if the resulting number cannot be represented with a fixed number of decimals (like 1/3). Please check the documentation of the div function for more details.

Usage

import Decimal from '@quentinadam/decimal';

const a = Decimal.from('1.11111111111111111111');

const b = a.mul(2);

console.log(b.toString()); // prints 2.22222222222222222222

const c = a.add(b);

console.log(c.toString()); // prints 3.33333333333333333333
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@quentinadam/decimal

Import symbol

import * as decimal from "@quentinadam/decimal";

---- OR ----

Import directly with a jsr specifier

import * as decimal from "jsr:@quentinadam/decimal";

Add Package

npx jsr add @quentinadam/decimal

Import symbol

import * as decimal from "@quentinadam/decimal";

Add Package

yarn dlx jsr add @quentinadam/decimal

Import symbol

import * as decimal from "@quentinadam/decimal";

Add Package

pnpm dlx jsr add @quentinadam/decimal

Import symbol

import * as decimal from "@quentinadam/decimal";

Add Package

bunx jsr add @quentinadam/decimal

Import symbol

import * as decimal from "@quentinadam/decimal";