Maintain trailing zeros in NumericTextBox

17 Feb 20221 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.

<ejs-numerictextbox id="numeric" value="10" decimals="2" format="n2" change="numericFocus" created="onCreate"></ejs-numerictextbox>
<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();
}