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

194
Visualizações
Floating point error while reading excel file from js

I am reading an excel file that has decimal, string, and Unicode characters when the user uploads it. I am seeing a floating point error when reading some decimal values(not all). For example, if a number is 0.15 then it is read as 0.150000000002. I need to compare data from the same excel file which is read and stored in DB to the data read from excel to find the difference in both. I am using xlxs-js and also tried using exceljs but was not able to resolve the issue.

   reader.onload = (e: any) => {
     /* read workbook */
     const bstr: any = e.target.result;
     const wb: XLSX.WorkBook = XLSX.read(bstr, {type: 'buffer'});

     /* grab first sheet */
     const wsname: string = wb.SheetNames[1];
     const ws: XLSX.WorkSheet = wb.Sheets[wsname];

     /* save data */
     this.data = (XLSX.utils.sheet_to_json(ws, {header: 1}));
     console.log(this.data)
   };
   reader.readAsArrayBuffer(target.files[0]);```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Javascript has some issues with floating point numbers.

For example:

0.1 + 0.2
=> 0.30000000000000004

If your floating point numbers all have the same amount of decimal places, I would recommend just removing these floating point digits.

parseFloat((0.1 + 0.2).toFixed(2))
=> 0.3

This is not very elegant and does not work if you have different amounts of decimal places.

I would need more information about how your this.data object looks to give you a code snippet to refactor your this.data object / array.

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