Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to convert float to integer or text – google apps script

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
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading