Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda