我剛開始學習編程,我選擇從 Google Apps Script 開始。我已按照教程進行操作,但由于某種原因,它要求我創建的函式根本沒有回傳預期值。我嘗試了許多不同的事情,例如更改代碼上的一些資訊,嘗試將相同的函式應用于作業表中的其他單元格,但作業表不斷回傳錯誤,我無法理解,因為代碼的執行不回傳錯誤,并且當我開始在單元格中寫她時,會顯示有關創建的新功能的預期資訊。
這是代碼:
/**
* 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);
}
然后,它要求我在單元格 "=salesPrice(100, .2)" 上寫,我寫下它并按 Enter,Sheets 回傳我 "#ERROR",當我嘗試更改此陳述句中的值時,如 "=salesPrice (100, *2)”它短暫顯示“正在加載...”,但隨后回傳“$NaN”。我嘗試做許多其他事情,但結果我一直收到錯誤,并且由于它只是一個初學者教程,因此預計它會起作用。提前致謝!
uj5u.com熱心網友回復:
根據您的語言環境(我猜),嘗試
=salePrice(100;0,2)
每個作業表的功能分隔符取決于從檔案>電子表格設定“區域設定”中選擇的國家 - 例如,如果您選擇美國,那么功能分隔符是逗號,但如果您選擇法國或巴西,那么它將是一個分號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/442737.html
標籤:谷歌应用脚本
