Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decimal.js

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decimal.js

An arbitrary-precision Decimal type for JavaScript.

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is decimal.js?

The decimal.js npm package is a library for arbitrary-precision decimal arithmetic. It allows for high-precision decimal calculations in JavaScript, which is particularly useful when dealing with financial calculations, scientific computations, or any other use case that requires more precision than JavaScript's native Number type can provide.

What are decimal.js's main functionalities?

Arithmetic Operations

Performing precise arithmetic operations like addition, subtraction, multiplication, and division without the floating-point errors that can occur with JavaScript's native Number type.

{"addition": "new Decimal('0.1').plus('0.2').toString()", "subtraction": "new Decimal('0.3').minus('0.1').toString()", "multiplication": "new Decimal('2').times('3').toString()", "division": "new Decimal('1').dividedBy('3').toString()"}

Comparison and Logical Operations

Comparing decimal numbers to determine equality, or whether one number is less than or greater than another. Also includes logical operations to check the sign of the numbers.

{"equals": "new Decimal('1.0').equals('1').toString()", "lessThan": "new Decimal('1').lessThan('2').toString()", "greaterThan": "new Decimal('2').greaterThan('1').toString()", "logicalAnd": "new Decimal('1').isPositive() && new Decimal('2').isPositive()"}

Chaining Operations

Allows chaining of multiple arithmetic operations in a single statement, which can make complex calculations more readable and concise.

{"chaining": "new Decimal('1.5').plus('1').minus('0.5').times('2').dividedBy('2').toString()"}

Configuration and Precision Control

Configuring the global settings of the library, such as the precision of calculations and the rounding mode to be used.

{"config": "Decimal.config({ precision: 5, rounding: 4 })"}

Other packages similar to decimal.js

Keywords

FAQs

Package last updated on 08 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc