Search results

Number Formats

You can format the value of NumericTextBox using format property. The value will be displayed in the specified format when the component is in focused out state. The format string supports both the standard numeric format string and custom numeric format string.

Standard formats

From the standard numeric formats, you can use the numeric related format specifiers such as n,p and c in the NumericTextBox component. By using these format specifiers, you can achieve the percentage and currency textbox behavior also.

The below example demonstrates percentage and currency formats.

razor
standard.cs
@section ControlsSection{

             <div id='container'>
                <div class='wrap'>
                    @Html.EJS().NumericTextBox("percent").Format("p2").Value(0.5).Min(0).Max(1).Step(0.01).Placeholder("Percentage format").FloatLabelType(FloatLabelType.Auto).Render()
                </div>
                <div class='wrap'>
                    @Html.EJS().NumericTextBox("currency").Format("c2").Value(10).Placeholder("Currency format").FloatLabelType(FloatLabelType.Auto).Render()
                </div>
            </div>
}
public ActionResult Standard()
{
    return View();
}

Output be like the below.

NumericTextBox Sample

Custom formats

From the custom numeric format string, you can provide any custom format by combining one or more custom specifiers.

The below examples demonstrate format the value by using currency format string # and 0.

razor
custom.cs
@section ControlsSection{

            <div id='container'>
                <div class='wrap'>
                    @Html.EJS().NumericTextBox("numeric").Format("###.##").Value(10).Placeholder("Custom format string #").FloatLabelType(FloatLabelType.Auto).Render()
                </div>
                <div class='wrap'>
                    @Html.EJS().NumericTextBox("numeric1").Format("000.00").Value(10).Placeholder("Custom format string 0").FloatLabelType(FloatLabelType.Auto).Render()
                </div>
            </div>
}
public ActionResult Custom()
{
    return View();
}

Output be like the below.

NumericTextBox Sample