how can i convert a number input so the first two numbers become decimals?

Just take the “actual value” of the input. Make sure to remove any decimal dot…. Parse it as an integer and divide by 100. Return. 😉

document.querySelector(".detailsInput").addEventListener("input", function(e){
  let actualValue = e.target.value.replace(".","")
  e.target.value=parseInt(actualValue)/100
})
<input type=number min=0.00 max=100.00 step=0.01 class='detailsInput' id='priceEntry' name='priceEntry' placeholder='Enter Price'>

=== Ho! If you insist on an inline version:

<input type=number min=0.00 max=100.00 step=0.01 class='detailsInput' id='priceEntry' name='priceEntry' placeholder='Enter Price' oninput="this.value=parseInt(this.value.replace('.',''))/100">

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top