javascriptjquerykendo-uikendo-asp.net-mvckendonumerictextbox

Kendo Numeric Text Box remove trailing zeros


I want to have a numeric textbox which can display these numbers like that :

Case 1 : 1,25 display 1,25

Case 2 : 1,50 display 1.5

Case 3 : 2,00 display 2

I just want to remove trailing zeros while playing with formats but I never find the right format to have all these case together.

This is the code : @(Html.Kendo().NumericTextBox().Spinners(false).Name("DosePrescriteNumericTextBox"))

And the initialisation :

let jqDoseNumericTextbox = $("#DosePrescriteNumericTextBox");
    jqDoseNumericTextbox.ready(function () {
        jqDoseNumericTextbox.data("kendoNumericTextBox").value(model.Dose);
    });

Thanks for your responses


Solution

  • The format you are looking for is "n" for number. This is actually the default format on the numeric text box, so if you omit the format attribute on your element, it will behave like this by default. If you want to explicitly state the format, here is some example code:

    @(Html.Kendo().NumericTextBox<double>()
      .Name("numeric")
      .Culture("en-US")
      .Value(1.50)
      .Format("n")
      .Placeholder("Enter numeric value")
      .HtmlAttributes(new { style = "width: 100%", title = "numeric" })
    )
    

    Note that my culture is set to the US, so I can use 1.50 instead of 1,50, you may have to adjust this for your region.