I’m trying to use the jquery-formatcurrency plugin.
I need to set the roundToDecimalPlace option to 0 by default. That is, I don’t want to specify that everytime I invoke jQueryObject.val().formatCurrency({roundToDecimalPlace: 0});
Instead, I just want to say jQueryObject.val().formatCurrency();
I tried setting it like this:
$.formatCurrency.defaults.roundToDecimalPlace = 0; but defaults is undefined.
I also tried $.formatCurrency.defaults = {roundToDecimalPlace: 0}; but that has no effect.
I found that $.formatCurrency only provides an object called region to configure, but doing $.formatCurrency.region.roundToDecimalPlace = 0; didn’t help.
You can’t just invent functionality for a plugin such as
defaults. It has to have the functionality programmed into the plugin, ready to be used.If you’re bothered about programming this more than once, create your own method that you can reuse again and again, but you have only defined
roundToDecimalPlaceonce.For example, the code below can have the jQueryObject passed to it and returns the formatted value back:
It can then be used again and again using: