Numeric Textbox Overview

The Blazor Numeric Textbox component allows the user to enter decimal values and no text. The developer can control minimum, maximum values, steps and other elements of the UX.

Telerik UI for Blazor Ninja image

The NumericTextBox component is part of Telerik UI for Blazor, a professional grade UI library with 90+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

To use a Telerik Numeric Textbox for Blazor, add the TelerikNumericTextBox tag.

Basic numeric textbox with its key features

The new value is: @theValue

<TelerikNumericTextBox Format="C" Max="5m" Min="-5m" Step="0.33m" @bind-Value="@theValue"></TelerikNumericTextBox>

@code {
     private decimal theValue { get; set; } = 1.234m;

The numeric textbox component is generic, meaning that it takes the type of its value parameter as an argument. It can take int, long, float, double and decimal values. Therefore, the values for the Min, Max and Step properties must be of the same type as the Value, and the ValueChanged handler must also accommodate the corresponding value type.

Component namespace and reference

@using Telerik.Blazor.Components

<TelerikNumericTextBox @ref="myNumericTextboxRef" @bind-Value="CurrentValue"></TelerikNumericTextBox>

@code {
    //determines the type of the component
    private int CurrentValue { get; set; }

    //the type of the value variable determines the type of the reference
    private Telerik.Blazor.Components.TelerikNumericTextBox<int> myNumericTextboxRef;

The numeric textbox provides the following features:

  • Arrows - whether the up/down spinner arrows (buttons) will be shown. Defaults to true.

  • Decimals - how many decimal places will be allowed while the user is typing a new value. Takes effect only while the input is focused. The default value is set from the specified culture.

  • Format - the format with which the number is presented when the input is not focused. Read more in the Standard Numeric Format Strings in .NET article.

  • Id - renders as the id attribute on the <input /> element, so you can attach a <label for=""> to the input.

  • Max - the maximum decimal value the input can take. Must be of the same type as the Value.

  • Min - the minimum decimal value the input can take. Must be of the same type as the Value.

  • Step - the decimal value of the step with which the value changes when the arrows are used. Must be of the same type as the Value.

  • Value - to get/set the value of the input.

  • Width - the width of the component. See the Dimensions article.

  • TabIndex - maps to the tabindex attribute of the HTML element. You can use it to customize the order in which the inputs in your form focus with the Tab key.

  • Validation - see the Input Validation article.

  • ValidateOn - configures the event that will trigger validation (if validation is enabled). Read more at Validation Modes for Simple Inputs.

Example of using a custom format strings

<br />
<TelerikNumericTextBox Format="#.00 kg" Max="5m" Min="-5m" Step="0.33m" @bind-Value="@Weight"></TelerikNumericTextBox>
<br />
    decimal Weight { get; set; } = 3.456789m;

<br />
<TelerikNumericTextBox Decimals="2" Format="@RentFormat" @bind-Value="@Rent"></TelerikNumericTextBox>
<br />
    decimal Rent { get; set; } = 4567.89m;
    string RentFormat { get; set; } = System.Globalization.NumberFormatInfo.CurrentInfo.CurrencySymbol + "#.00 a year";

<br />
<TelerikNumericTextBox Decimals="0" Format="@UnitsFormat" @bind-Value="@Units"></TelerikNumericTextBox>

    int Units { get; set; } = 12;
    string UnitsFormat { get; set; } = "# unit(s)";


  • If you want to use a currency format, you must specify the culture for your app thread, so .NET knows what symbol to render. If you don't do that, you may see an unexpected/incorrect symbol or format. The Telerik Numeric Textbox uses the thread culture for currency signs and decimalr separators (more on globalization in the Telerik components).

  • You may want to match the decimal places available in the Format and in the Decimals parameters. This will unify the rounding of the numbers when the input is focused and when it is not. For example, if you start with a value 12.3m and Step=0.1m it will render as 12.3 due to the Math.Round() behavior in .NET. Changing the value with the spinner icons up and then down will result in 12.30 because the value had had a second decimal digit at some point and that precision is added to the number already.

    Here is an example of matching the decimal places:


    @DecimalStepValue.ToString("N2") <br />
    <TelerikNumericTextBox @bind-Value=@DecimalStepValue 
    @code {
        decimal DecimalValue = 12.3m;

See Also

In this article
Not finding the help you need? Improve this article