O'Reilly logo

CoffeeScript Application Development Cookbook by Mike Hatfield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Formatting numbers with accounting.js

The accounting.js module can be used to parse strings into numeric values as we saw earlier in this chapter. It is also very good at preparing numbers for display and provides a number of functions to help with this.

In this recipe, we will look at various methods to display numbers using accounting.js.

Getting ready

Before we begin, let's make sure the accounting.js NPM module is installed:

npm install accounting --save

How to do it...

In this example, we will demonstrate ways to use accounting.js to format numbers:

  1. Load the accounting module:
    accounting = require 'accounting'
    
  2. Use the formatMoney() function:
    # formatting as currency (default formatting)
    console.log accounting.formatMoney 31415.9535
    console.log ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required