Home > Net >  how to convert float to integer or text - google apps script
how to convert float to integer or text - google apps script

Time:06-29

The following function returns a float number (.0) how can i convert it to integer, or text? Thanks!

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
}

CodePudding user response:

const cloud = 9.0
console.log(cloud.toFixed(0))
console.log(cloud.toString())
console.log(String(cloud))

You can use cloud.toFixed(0) for removing that decimal.

You can use cloud.toString() or in ES6 String(cloud)

Reference:-

toFixed()

toString()

  • Related