Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Google Apps Script JSON element to Float

I'm using the following script on Google Apps Script to retrieve the value of my Helium wallet:

function getBalance() {
  try {
    var url = 'https://api.helium.io/v1/accounts/1451THihiR9hDzkgdn4ZMSTzC8cuQJh9StXJGVPEcTPEXjKzjdH'
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
    var data = JSON.parse(response.getContentText());
    var balance = data.data.balance;
    var myTime = new Date();
    Logger.log(balance);
    Logger.log(myTime);
  } catch (err) {
    Logger.log(data)
    Logger.log(err.message);
  }
}

My issue is that the number that is returned as balance is:

9:26:42 PM  Info  5.08178108E8

The balance is actually 5.08178108. I want to convert the element into a Float but I can't find a way to do that. Converting it to a string removes the decimal. How do I convert the balance into a Float while retaining the decimal position?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks to tanaike for this answer:

I ended up converting the balance into a Float by dividing by 1E8. Here's the entire function:

function getBalance() {
  try {
    var url = 'https://api.helium.io/v1/accounts/1451THihiR9hDzkgdn4ZMSTzC8cuQJh9StXJGVPEcTPEXjKzjdH'
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
    var data = JSON.parse(response.getContentText());
    var balance = data.data.balance / 1E8;
    var myTime = new Date();
    Logger.log(balance);
    Logger.log(myTime);
  } catch (err) {
    Logger.log(data)
    Logger.log(err.message);
  }
}

This allowed me to set the value in my Google Sheet and make calculations off of it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!