Custom function quickstart  |  Apps Script  |  Google for Developers

PHOTO EMBED

Tue Oct 31 2023 15:51:00 GMT+0000 (Coordinated Universal Time)

Saved by @Spsypg #javascript

/**
 * Calculates the sale price of a value at a given discount.
 * The sale price is formatted as US dollars.
 *
 * @param {number} input The value to discount.
 * @param {number} discount The discount to apply, such as .5 or 50%.
 * @return The sale price formatted as USD.
 * @customfunction
 */
function salePrice(input, discount) {
  let price = input - (input * discount);
  let dollarUS = Intl.NumberFormat("en-US", {
    style: "currency",
    currency: "USD",
});
  return dollarUS.format(price);
}
content_copyCOPY

https://developers.google.com/apps-script/quickstart/custom-functions