1

I have the following calculation that I would like to format as a currency:

jQuery(function () {

  $("#weight").change(function () {
    var iva = $("#iva").val();
    var subtotal = $("#subtotal").val();
    var total = parseFloat(iva) + parseFloat(subtotal);

    $("#total").val(total.toFixed(2));
  })
})

I have tried the numeral.js plug in change the last line to:

$("#total").val(total.format('$0,0.00'));

but this is not working (no calculation at all.

What is the proper way to use the plugin in this instance?

Thanks for any help!

twernt
  • 20,271
  • 5
  • 32
  • 41
penone
  • 742
  • 1
  • 10
  • 27

1 Answers1

0

You'll need to call the numeral() function on total to use the plugin's format() function:

$("#total").val(numeral(total).format('$0,0.00'));

This creates a Numeral object with a value of total.

twernt
  • 20,271
  • 5
  • 32
  • 41