Maintain Trailing Zeros in ASP.NET MVC NumericTextBox
21 Aug 20261 minute to read
By default, trailing zeros disappear when the NumericTextBox gets focus. However, you can use the following sample to maintain the trailing zeros while focusing the NumericTextBox.
@Html.EJS().NumericTextBox("numeric").Format("n2").Value(10).Decimals(2).Change("numericFocus").Created("onCreate").Render()
<script>
function numericFocus() {
var numericObj = this.ej2_instances ? this.ej2_instances[0] : this;
numericObj.element.value = numericObj.formattedValue(numericObj.decimals, +numericObj.element.value);
}
function onCreate() {
document.getElementById('numeric').addEventListener('focus', numericFocus);
}
</script>public ActionResult nullableInput()
{
return View();
}