Last Updated: February 25, 2016
·
875
· 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.