![](/img/trans.png)
[英]How to set null in decimal type in mysql through JDBC on google apps script
[英]How to set the result to 2 decimal places in google apps script
我有以下代碼並要求結果有 2 位小數
function TotalVat() {
const ss = SpreadsheetApp.openById('1BAj2E_xv3bz_Fnt0Xcm5UidGapZhVWeJ6gA5w3-Vnsj');
const sh = ss.getSheetByName("JOBS");
const vs = sh.getRange(2, 1, sh.getLastRow() - 2, sh.getLastColumn()).getValues();
vs.forEach((r,i) => {
sh.getRange(i + 2,38).setNumberFormat("0.#0").setValue(r[35] * (r[36]/100));
});
}
電子表格上的格式是 2 位小數,但我也通過 email 發送結果,這里計算的結果超過 2 位小數。 任何幫助將不勝感激。 謝謝
嘗試:
sh.getRange(i + 2,38).setValue(r[35] * (r[36]/100).setNumberFormat("0.00")
這對我有用:
function TotalVat() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const vs = sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).getValues();
vs.forEach((r, i) => {
sh.getRange(i + 2, 3).setValue(r[0] * (r[1] / 100)).setNumberFormat("0.00");
});
}
列1 | 列2 | |
---|---|---|
3個 | 10 | 0.30 |
9 | 8個 | 0.72 |
5個 | 15 | 0.75 |
11 | 12 | 1.32 |
0 | 13 | 0.00 |
0 | 19 | 0.00 |
7 | 15 | 1.05 |
18 | 17 | 3.06 |
18 | 1個 | 0.18 |
11 | 17 | 1.87 |
9 | 15 | 1.35 |
3個 | 3個 | 0.09 |
17 | 16 | 2.72 |
2個 | 4個 | 0.08 |
3個 | 13 | 0.39 |
3個 | 8個 | 0.24 |
19 | 1個 | 0.19 |
19 | 5個 | 0.95 |
2個 | 8個 | 0.16 |
15 | 10 | 1.50 |
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.