i've just started to learn programming, and i have choosed to start with Google Apps Script. I have followed the tutorial, but for some reason the function it asks me to create simply doesn't return the expected value. I tried many different things like change some information on the code, tried to apply the same function to other cells in sheet's, but sheet's keep returning error, and i can't understand since the execution of the code doesn't return error, and the expected information about the new function created shows up when i start writing her in a cell.
Here is the code:
/**
* 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);
}
It then, asks me to write on cell "=salesPrice(100, .2)" , i write that and hit enter, and Sheets returns me "#ERROR" and when i try to change the values inside this statement like "=salesPrice(100, *2)" it briefly shows "loading..." but then return "$NaN". I tried to do many other things but i keep receiving error as a result, and it was expected to work since it is just a beginner tutorial. Thanks in advance!
CodePudding user response:
Depending on your locale (I guess), try
=salePrice(100;0,2)
The function separator for each Sheet is dependent on the the country chosen from File> Spreadsheet setting "Locale" - For example if you choose United States then function separator is comma but if you choose France or Brazil for instance then it will be a semicolon.