1

Firefox shows just 1 when I type 1,00 in the input. All other browsers I tested are showing 1,00. How can I read the full value of the input in Firefox with the zeros after the comma? The type of the input has to be number and can't be text.

$("#input").keyup(function() {
  $("#output").text($("#input").val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="input" min="0.00" step="0.01" max="999.99">
<p id="output"></p>

Edit: For me it doesn't matter if decimal mark is a comma or a period. See the Screenshot of the difference between Chrome and Firefox.

Virinum
  • 31
  • 5

2 Answers2

0

let output = document.getElementById('output');

document.getElementById('input').addEventListener('input', function (e) {
  output.innerText = e.currentTarget.value.replace('.', ',');
});
<input type="number" id="input" min="0.00" step="0.01" max="999.99">
<p id="output"></p>
Piterden
  • 771
  • 5
  • 17
0

You can parse the value to a float and use the toFixed function to always print the number with two decimals.

$("#input").keyup(function() {
  $("#output").text(
    parseFloat($("#input").val()).toFixed(2)
  );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="input" min="0.00" step="0.01" max="999.99">
<p id="output"></p>
Jerodev
  • 32,252
  • 11
  • 87
  • 108