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

dinero.js

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dinero.js

An immutable library to create, calculate and format monetary values.

  • 1.9.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132K
decreased by-16.33%
Maintainers
1
Weekly downloads
 
Created

What is dinero.js?

Dinero.js is a library for working with monetary values in JavaScript. It provides a comprehensive API for creating, manipulating, and formatting monetary amounts, ensuring precision and avoiding common pitfalls associated with floating-point arithmetic.

What are dinero.js's main functionalities?

Creating Dinero Objects

You can create Dinero objects by specifying the amount in minor currency units (e.g., cents) and the currency code.

const Dinero = require('dinero.js');
const amount = Dinero({ amount: 5000, currency: 'USD' });

Arithmetic Operations

Dinero.js allows you to perform arithmetic operations like addition, subtraction, multiplication, and division on monetary amounts.

const Dinero = require('dinero.js');
const amount1 = Dinero({ amount: 5000, currency: 'USD' });
const amount2 = Dinero({ amount: 3000, currency: 'USD' });
const sum = amount1.add(amount2);

Formatting

You can format Dinero objects into human-readable strings using various formatting options.

const Dinero = require('dinero.js');
const amount = Dinero({ amount: 5000, currency: 'USD' });
const formatted = amount.toFormat('$0,0.00');

Comparisons

Dinero.js provides methods to compare monetary amounts, such as checking if one amount is greater than, less than, or equal to another.

const Dinero = require('dinero.js');
const amount1 = Dinero({ amount: 5000, currency: 'USD' });
const amount2 = Dinero({ amount: 3000, currency: 'USD' });
const isGreater = amount1.greaterThan(amount2);

Currency Conversion

Dinero.js supports currency conversion given a set of exchange rates.

const Dinero = require('dinero.js');
const amount = Dinero({ amount: 5000, currency: 'USD' });
const converted = amount.convert('EUR', { rates: { USD: 1, EUR: 0.85 } });

Other packages similar to dinero.js

Keywords

FAQs

Package last updated on 10 Oct 2021

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