以下函數返回浮點數(.0)。如何將其轉換為整數或文本?謝謝
function test(){
const url = "https://www.7timer.info/bin/astro.php?lon=113.2&lat=23.1&ac=0&unit=metric&output=json&tzshift=0";
const res = UrlFetchApp.fetch(url);
const data = JSON.parse(res.getContentText());
var cloud = data.dataseries[0].cloudcover;
Logger.log(cloud); //result is 9.0
}
您可以使用
cloud.toFixed(0)
刪除該小數點。您可以使用
cloud.toString()
或在ES6String(cloud)
Reference:-
toFixed()
toString()