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

92
Views
¿Cómo puedo mostrar la salida en solo 2 decimales?

 <!DOCTYPE html> <html lang="en"> <head> </head> <body translate="no"> <input type="number" placeholder="user enter's here" name="price" id="get" /> <input type="number" name="reduced" value="0.0039" id="qty_1" /> <input type="number" placeholder="output" name="total" id="send" readonly /> <script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-1b93190375e9ccc259df3a57c1abc0e64599724ae30d7ea4c6877eb615f89387.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script id="rendered-js"> $(function () { $("#get, #reduced").keyup(function () { var input = $("#get").val() || 0; var input2 = $("#reduced").val() || 0; $("#send").val(input - input2); }); }); //# sourceURL=pen.js </script> </body> </html>

Tengo un código que resta la cantidad que ingresa el usuario y cuando el usuario ingresa un número decimal, mostrará un número muy largo. ¿Cómo puedo acortarlo a dos lugares ? 39409.44 Intenté agregar .tofixed(2) y otro no funcionó

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puedes usar toFixed()

 //... var price = parseFloat($("#price_1").val()).toFixed(2); var qty = parseFloat($("#qty_1").val()).toFixed(2); //...
about 4 years ago · Santiago Trujillo Report

0

Pruebe el siguiente código, también tiene en cuenta el escenario en el que la entrada también tiene un número no válido:

 $("#get, #reduced").keyup(function () { var input = parseFloat($("#get").val()) || 0.0; var input2 = parseFloat($("#reduced").val()) || 0.0; var result = parseFloat(input - input2).toFixed(2) $("#send").val(result); });

Espero eso ayude.

about 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!