GitXplorerGitXplorer
u

bigdenary

public
11 stars
2 forks
3 issues

Commits

List of commits on branch master.
Verified
03ad45cf54806758de4f964a66bfb4a66ae18140

Fixes rounding for negative number

uuzyn committed 5 years ago
Verified
44fd767fd0ebe2e5e3b8df9f5cc5d2ae404ffb63

Prroper rounding

uuzyn committed 5 years ago
Verified
aeee6f1b953708e763eed158a890d0a01c7e7dac

Fixed a test

uuzyn committed 5 years ago
Verified
7c1907da2f309b5dda4cf50031032587c3bd6b14

division fix

uuzyn committed 5 years ago
Verified
22f97c2c9e512eff2506a237362009f2e68ebbc7

Fixes toString() bug for neg number

uuzyn committed 5 years ago
Verified
e72972a1e9d33ca93766d124d95472cecc30a084

Merge pull request #8 from uzyn/toFixed

uuzyn committed 5 years ago

README

The README file for this repository.

BigDenary

Arbitrary-length decimal implementation using JavaScript's native BigInt with no dependencies.

  • Supported on Node >= 10.4 and Deno.
  • Check caniuse.com for browser support.

Features

  • Deno module first. Soon to be available as ES Module (ESM) and CommonJS (Node) module.

  • Compute methods are largely implemented through native BigInt, without much string manipulation required.

  • Standalone & lightweight. Zero dependencies.

  • Intuitive data structure – base amount and decimal places, similar to that of cryptocurrency esp. Bitcoin.

  • API is similar with the popular BigNumber libraries such as bignumber.js, big.js, decimal.js. Not all methods are supported, yet.

Usage

import { BigDenary } from "https://deno.land/x/bigdenary/mod.ts";

const bd = new BigDenary("123.4512");
const sum = bd.add(56.1e2);

console.log(sum.toString()); // 5733.4512
console.log(sum); // BigDenary { base: 57334512n, _decimals: 4 }

API is largely inspired by and attempts to be compatible with decimal.js-light.

Available API

Core

  • constructor(): supports type BDNumberInput = number | string | bigint | BigDenary | BigDenaryRaw.
  • toString(): Returns string representation
  • valueOf(): Returns number approximation
  • toFixed(digits?): Returns string representation to the number of digits to appear decimal point.

Operations

  • plus() or add()
  • minus() or sub()
  • multipliedBy() or mul()
  • dividedBy() or div()
  • negated() or neg()
  • absoluteValue() or abs()

Comparisons

  • comparedTo() or cmp()
  • equals() or eq()
  • greaterThan() or gt()
  • greaterThanOrEqualTo() or gte()
  • lessThan() or lt()
  • lessThanOrEqualTo() or lte()

Develop and running of tests

  1. Install Deno

  2. Run unit tests

deno test

Notes

JavaScript native decimal support is currently being proposed (Stage 1) to ECMA.

License

MIT · U-Zyn Chua

Contributions are welcomed.