monster.util.formatPrice()#

Syntax#

monster.util.formatPrice(price[, decimals]);

Parameter#

price: String OR Number (mandatory)#

Price to format (either a number or a string representation of a number).

decimals: String OR Number (optional)#

The number of decimals that will shown. If not specified, integer will show no decimals and floats will show two decimals.

Return#

This method returns a String representation of the provided price, showing the specified number of decimals.

Description#

The monster.util.formatPrice() method is used to easily format prices.

Examples#

  • Formatting prices
monster.util.formatPrice(3);
// output: "3"
monster.util.formatPrice("3.3");
// output: "3.30"
monster.util.formatPrice(3.3333);
// output: "3.33"

monster.util.formatPrice(5, "3");
// output: "5.000"
monster.util.formatPrice("5.5", 3);
// output: "5.500"
monster.util.formatPrice("5.5555", "3");
// output: "5.555"

Edit this page here