Home > Software engineering >  Kendo CurrencyTextBox displays 200.00 as 20000
Kendo CurrencyTextBox displays 200.00 as 20000

Time:01-24

I am using kendo UI to create an input box, I want to automatically display the amount user have to pay in the textbox before, so that user will only have to insert an amount if it differs from default The data is given as decimal number.

I have tried:

@(Html.Kendo().CurrencyTextBoxFor(model => model.Paid).Format("R#0.00").Min(0))

And now also:

@(Html.Kendo().NumericTextBoxFor<decimal>(model => model.Paid).Format("R#.##").Min(0))

for some reason the textbox just keeps displaying two extra zeros

CodePudding user response:

For some reason the textbox just keeps displaying two extra zeros

Yes, as per my investigation upon your code snippet it might be because of your default-culture. However, we can customize it as per the requirement. You could follow below steps:

Program.cs:

var defaultCulture = "en-US";
var ci = new CultureInfo(defaultCulture);
ci.NumberFormat.NumberDecimalSeparator = "."; // Defining my preferrence for number
ci.NumberFormat.CurrencyDecimalSeparator = ".";

// Configuring Number Seperator Using Localization middleware
app.UseRequestLocalization(new RequestLocalizationOptions
{
    DefaultRequestCulture = new RequestCulture(ci),
    SupportedCultures = new List<CultureInfo>
    {
        ci,
    },
    SupportedUICultures = new List<CultureInfo>
    {
        ci,
    }
});

Note: As you can see in NumberFormat.NumberDecimalSeparator I am setting my preferrence for seperator. You are open to use anything you want, any kind of charaters. Please consider the order as well while placing the code in middleware. Best use would be end of your current middleware. As following:

enter image description here

Update for Classic Asp.net 4.8 and Older:

We can configure above steps for asp.net classic project as well. To set the UI culture and culture for all pages, enter image description here

Note: For further reference you could check our official document below.

  1. Custom numeric format strings
  2. The "." custom specifier
  • Related