优化 input 数字输入框组件的小数点后保留位逻辑

pull/1299/head
贤心 2023-07-03 00:25:44 +08:00
parent ec2bddd27b
commit 0b7577099c
1 changed files with 4 additions and 3 deletions

View File

@ -293,10 +293,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
if(value < min) value = min; if(value < min) value = min;
if(value > max) value = max; if(value > max) value = max;
// 保留位数 // 小数点后保留位数
value = value.toFixed(function(step){ var fixed = function(step){
return (step.match(/(?<=\.)[\d]+$/) || [''])[0].length; return (step.match(/(?<=\.)[\d]+$/) || [''])[0].length;
}(step.toString())); }(step.toString());
if(fixed) value = value.toFixed(fixed);
elem.val(value); elem.val(value);
} }