简体   繁体   English

有没有办法抑制<input type =“number”>的科学记数法?

[英]Is there a way to suppress scientific notation for <input type=“number”>?

I'd like to input numbers with up to eight decimal points with an <input> element. 我想用<input>元素<input>最多8个小数点的数字。 However, if I have an <input type="number" step="0.00000001"> and use the up/down arrows on the input element (on Chrome; here's the jsfiddle ), then I get scientific notation for the small numbers: 但是,如果我有一个<input type="number" step="0.00000001">并使用输入元素上的向上/向下箭头(在Chrome上;这里是jsfiddle ),那么我会得到小数字的科学记数法:

在此输入图像描述

If I input, say, 5, and then hit the arrow key, then scientific notation is suppressed: 如果我输入5,然后按箭头键,则会抑制科学记数法:

在此输入图像描述

Is there any way to get the browser to display the 1e-8 as 0.000000001 ? 有没有办法让浏览器将1e-8显示为0.000000001

Also, is there any danger here that with sufficiently small numbers, I'll hit floating point rounding errors? 此外,这里是否有任何危险,如果数量足够小,我会遇到浮点舍入错误?

 <input type="number" step="0.00000001"> 

 <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. 您可以根据需要将toFixed参数更改为所需的小数位数。 I hope this helps! 我希望这有帮助!

以下是基于StardustGogeta 答案的变体:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angularjs避免使用数字滤波器的科学记数法 - Angularjs avoid scientific notation for number filter 抑制数字值 Output 中的科学记数法 Html 格式 email 写在 ZA781172326B5629 中 - Suppress the Scientific Notation in Numeric Value Output in Html formatted email written in Python 有没有办法在 type=“number” 输入字段中捕获字母? - Is there a way to capture Letters in a type=“number” input field? 有没有办法只允许使用输入类型=“数字”上的微调控件进行输入? - Is there a way to ONLY allow input using the spinner controls on an input type=“number”? 科学计数法在表格中显示为十进制 - scientific notation displayed as decimal in table 有没有办法像使用 type=“search” 一样清除输入 type=“number” - Is there a way to clear an input type=“number” like when using type=“search” 输入类型范围min属性中的AngularJS表示法 - AngularJS notation in input type range min attribute 有什么办法可以防止 input type="number" 得到负值吗? - Is there any way to prevent input type="number" getting negative values? 有没有办法使这种输入数字类型起作用? [HTML5] - Is there a way to make this input number type work? [HTML5] 造型<input type=number/>以正确的方式旋转箭头 - Styling <input type=number/> spinner arrows the right way
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM