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

97
Views
how can i show the output in only 2 decimals

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

i do have a code which substract the amount user enter's and when user enter an decimal number it will show very long number how can i short it to two places 39409.44 i tried adding .tofixed(2) and other didn't work

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use 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

Try the below code, it also takes into consideration the scenario where input has invalid number entered as well:

$("#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);
  
});

Hope it helps.

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!