@aficion360/decimal

A simple arbitrary-precision Decimal class for TypeScript

Usage no npm install needed!

<script type="module">
  import aficion360Decimal from 'https://cdn.skypack.dev/@aficion360/decimal';
</script>

README

Decimal

A simple arbitrary-precision Decimal type for TypeScript.

  • Accept Number, String, Null and NaN values.
  • No dependecies.
  • Immutable data structure.
  • Secure operations, like add, substract or multiply. Ex: 0.1 + 0.2 = 0.3.
  • Tested classes.

Use

Create instances:

const decNull = new Decimal(null);
const decNaN = new Decimal('euro');
const dec10 = new Decimal(10);
const dec30 = new Decimal('30 euros');

Chain operations:

// Output: "0.3"
new Decimal(0.1).add(0.2).toString();

AficiĆ³n 360

Enjoy it ;-)