Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

64
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda