Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Latest commit

 

History

History
38 lines (25 loc) · 1.41 KB

File metadata and controls

38 lines (25 loc) · 1.41 KB

BigDecimal number converter

A very small set of utility functions to convert numbers in Big Decimal format to JavaScript numbers and back.

version styled with prettier

Install

npm install --save @exante/big-decimal

Usage

import { toBigDec, fromBigDec } from '@exante/big-decimal';

fromBigDec({ scale: 2, value: 12345 }); // -> 123.45

toBigDec(123.45); // -> { scale: 2, value: 12345 }

Features

  • Robust: The library is tested to behave correctly with all kinds of input. It correctly handles all JavaScript quirks when dealing with numbers and accounts for strings, scientific notation, leading and trailing zeros and invalid input.
  • Lightweight: 800 bytes minified

NOTE: Does not provide BigDecimal arithmetic

This library is intended to be as lightweight as possible. Therefore it only provides helpers to convert numbers to and from BigDecimal format. It does not provide utilities for BigDecimal arithmetic. If you need precision arithmetic in JavaScript, take a look at big.js or bignumber.js