Last Updated: February 25, 2016
·
1.073K
· cdmwebs

Format/unformat Ember.js computed properties with accounting.js

App = Ember.Application.create();

App.IndexController = Ember.ObjectController.extend({
  amount: 100,

  formattedAmount: function(key, value) {
    if (arguments.length > 1) {
      // setter
      var cleanAmount = accounting.unformat(value);
      this.set('amount', cleanAmount);
    }

    return accounting.formatMoney(this.get('amount'));
  }.property('amount')
});

Demo JS Bin.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside