[英]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">
以下是基于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.