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

187
Visualizações
Data Saved as Strings, But need Ints

I am retrieving data from a table. The data is numbers, but it was saved as TINYTEXT in the mySql database. I can retrieve it and access it just fine, but I'm running into trouble because I need to add numbers.

So while I want 4 + 5 + 3 = 12.... instead I get the result of "453".

This is my calculation on the retrieved data:

let consultingScore = 0;
let consultingScoreDiv = 0;
   for (let i = 0; i < result.length; i++){
   let tempConScore = result[i].formValue01 + 
   result[i].formValue02 + result[i].formValue03;

   consultingScore = consultingScore + tempConScore;

   this.setState({ surveyScoreConsulting: consultingScore }); <--- (This should be 12, but is instead "453"
                }

I have tried to use parseInt() like below, but when I do, then the value then becomes NaN. Am I not using parseInt correctly? It seems it should be easier than this to convert sting numbers to integers so I can perform calculations with them.

let consultingScore = 0;
let consultingScoreDiv = 0;
   for (let i = 0; i < result.length; i++){
   let tempConScore = parseInt(result[i].formValue01) + 
   parseInt(result[i].formValue02) + parseInt(result[i].formValue03);

   consultingScore = consultingScore + tempConScore;

   this.setState({ surveyScoreConsulting: consultingScore }); <--- (This should be 12, but is instead "453"
                }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to parse with base 10, like this parseInt(yourValue, 10)

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