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

63
Visualizações
JavaScript converting floating Numbers to Integer overflowing on certain Values

I was trying to implement a form which has a text box that accepts an input from user and converts it to double for sending post request. Example as below.

Image 1

The issue is the input from user is in string format, so I am doing something like, whenever that is onChange then convert it to val/100 and save as double in the state and when displaying on UI display as val*100.All the Values as being displayed correctly but only problem is with Value 7, which overflows to 7.00000001, I am not able to figure out why does it happens. Inside debugger the Value is showing 0.07 and 7 only. See below for the Error.

Error Facing

<TextBox 
   value={getConvertedValue()}
   onChange={changeHandler}   
/>

function getConvertedValue() {
    return (MobxObservable * 100).toString; 
}

changeHandler(event: React.FormEvent, val: string) => {
   // apAction function that sets the value in store.
   setValue(Number(val)/100);
}

Problem - I cannot use Math.round since user wants to enter 1.25 also, toFixed() cannot be used as entering 3 would be then displayed as 3.00 which I doesn't wanted.

What can be the possible solution for this. Tried with available methods but didn't work.

about 4 years ago · Juan Pablo Isaza
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