0

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

Community
  • 1
  • 1
Drallireeh
  • 17
  • 6

1 Answers1

2

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.

  • The problem is the value is still displayed with trailing zeros. In your example, you put 1.50 in value, and it displays the same. I'm looking for a format which display 1.5 in this case, and if my value is 2, I want to have a 2 instead of 2.00 – Drallireeh Jun 05 '20 at 11:11
  • Strange, I have tested and don't see the trailing zeros. Are you using this in asp.net in a razor page? Maybe you can adjust your answer with your code so I can test it. – MentallyRecursive Jun 08 '20 at 17:15