Coder Social home page Coder Social logo

decimal's Introduction

DecimalX

DecimalX is a high-precision decimal arithmetic library for JavaScript and TypeScript, providing an easy-to-use API for performing arithmetic operations on decimal numbers.

This package is designed to handle calculations with a large number of decimal places, ensuring accuracy and performance in financial applications, scientific computations, and wherever else precise decimal arithmetic is required.

To get started with DecimalX, install the package using npm:

npm install decimalx

Usage

import { DecimalFactory } from 'decimalx';

// precision is total number of numbers allowed
// scale is the portion of the total that should be right of the decimal point
let Decimal = DecimalFactory({ precision: 20, scale: 2})
let decimalA = new Decimal('10.6');
let decimalB = new Decimal('2.3');

let sum = decimalA.add(decimalB);
let difference = decimalA.subtract(decimalB);
let product = decimalA.mul(decimalB);
let distribution = decimalA.distribute(3);

console.log(sum.valueAsString()); // '12.90'
console.log(difference.valueAsString()); // '8.30'
console.log(product.valueAsString()); // '24.38'
console.log(distribution.map(d => d.valueAsString())); // ['3.50', '3.50', '3.60']

The Decimal class also provides the following methods for different representations:

  • valueAsBigint() - Returns the value as a BigInt
  • valueAsNumber() - Returns the value as a number
  • valueAsString() - Returns the value as a string
  • definition() - Returns the precision and scale used for the Decimal

decimal's People

Contributors

mofax avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.