Dinero.js: Working With Monetary Values in JavaScript

Home » Blog » Software » Web Applications » Dinero.js: Working With Monetary Values in JavaScript

Working with monetary values can become a problem in any programming language and JavaScript certainly is no different in that respect.

The naïve assumption that monetary values can be expressed as floating point numbers almost inevitably leads to rounding errors caused by precision and the fact that in most cases monetary values are represented as decimal numbers with just two (instead of an undefined number of) decimal places. Apart from that, money is not just a number but usually comprises a currency denominator such as £, € or $.

In order to alleviate these problems there are design patterns such as the Money pattern by Martin Fowler and classes / APIs such as BigDecimal in Java.

In addition to the issues mentioned before JavaScript also has no specific type for monetary values, which is why software engineer Sarah Dayan created Dinero.js – a library for working with monetary values in JavaScript.

She has also published an article on how to handle monetary values in JavaScript, in which she describes common problems, their respective solutions and the rationale behind Dinero.js.

Leave a Comment

*

I agree