? I would like to enter numbers accurate to eight decimal points with the...">

Is there a way to suppress scientific notation for <input type = "number">?

I would like to enter numbers accurate to eight decimal points with the <input> element. However, if I have <input type="number" step="0.00000001"> and use the up / down arrows for the input element (in Chrome, here is jsfiddle ) then I get scientific notation for small numbers:

enter image description here

If I enter, say, 5, and then press the arrow key, then the scientific notation will be suppressed:

enter image description here

Is there a way to get the browser to display 1e-8 as 0.000000001 ?

In addition, is there a danger here that with sufficiently small numbers I will remove the floating point rounding errors?

 <input type="number" step="0.00000001"> 
+6
source share
2 answers

 <input oninput='precise(this)' type="number" step="0.00000001"> <script> function precise(elem) { elem.value = Number(elem.value).toFixed(8); } </script> 

You can change the toFixed parameter to the desired number of decimal digits as needed. Hope this helps!

+4
source

Here is an option based on the StardustGogeta answer :

 <input oninput="this.value=Number(this.value).toFixed(this.step.split('.')[1].length)" type=number step="0.00000001"> 
+2
source

All Articles