1.js:
//保留2位小数,如:2,会在2后面补上00.即2.00
function toDecimal2(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x * 100) / 100;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
2.页面调用
<div class="input_inline mt10 pb6 pt6" style="width:auto;">
<label style="min-width:8em;">@Util.GetLanguageItemTextByController("lblcs12", controllerName)</label>
<input type="number" name="MSTC" value="" οnblur="this.value=toDecimal2(this.value)" required>
</div>