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

499
Views
¿Por qué mi función toFixed() no funciona?

Aquí está el código relevante. Confirmé con la alerta que se guardó el número correcto, solo que no se cambió a 2 decimales.

 if ($(this).attr('name') == 'time') { var value = $(this).val(); parseFloat(value).toFixed(2); alert(value); editEntry.time = value; }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

No está asignando el flotante analizado de nuevo a su valor var:

 value = parseFloat(value).toFixed(2);

debería arreglar las cosas.

over 4 years ago · Santiago Trujillo Report

0

Probé la función toFixed(2) muchas veces. Cada vez que la consola muestra "toFixed() no es una función".

pero cómo lo resolví es usando Math.round()

p.ej:

 if ($(this).attr('name') == 'time') { var value = parseFloat($(this).val()); value = Math.round(value*100)/100; // 10 defines 1 decimals, 100 for 2, 1000 for 3 alert(value); }

esto seguramente funciona para mí y podría ayudarlos a ustedes también...

over 4 years ago · Santiago Trujillo Report

0

Su valor no debe ser un número entero, así que agregue 0 para convertir su valor en un número entero y luego toFixed() funcionará.

over 4 years ago · Santiago Trujillo 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!