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

292
Vistas
How to do an addition in javascript with float number?

I'm trying to do something really stupid, but maybe it will be my careless mistake ... In short, how is it possible that in a simple function like this:

function limitFunc(name){
  var domain=prompt(`Inserisci il dominio della funzione`);
  var sx=domain-0.2;
  var dx=domain+0.2;
  console.log(`sx`,sx, `dx:`,dx);
  //console.table(graph.limitCalculation(name, domain));
}

If I then write 1 with the prompt, the dx variable then calculated gives me a number multiplied by 10.

For example if I write 1: chrome console

Thanks for the help anyway

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

prompt returns a string.

All you need to do is convert your string into a number, basically:

function limitFunc(name) {
    let domain = prompt(`Inserisci il dominio della funzione`);
    domain = +domain; // converted string into number
    const sx = domain - 0.2;
    const dx = domain + 0.2;
    console.log(`sx:`, sx, `dx:`,dx);
}

limitFunc();

Obviously, you'd want to check if the user prompts a valid answer (i.e. a number).

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