Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!