Duplicated
Last Updated: 04 Aug 2023 07:42 by ADMIN
Jack
Created on: 28 Jul 2023 22:35
Category: UI for Blazor
Type: Bug Report
2
TelerikNumericTextBox.Decimals default value should NOT be tied to the user's culture

Per API documentation, the Decimals property defaults to what is set in the user's region (culture). This is a flawed design.

Why would one think that ALL properties of type double or float in grid models should be truncated to 2 decimal places (when my region is set to US and that is the default)?

This seriously limits property values. Not everything is a dollar and cent value! The region setting I believe is for how to format general currency values perhaps (I am not exactly sure what it is for, because there is a different tab for 'Currency' with a 'No. of digits after decimal' setting as well as the tab for 'Numbers' having the same thing. But this does not mean that Windows always formats numbers that way.

Suppose for example I have a property in my model named "Weight" (expressed in terms of pounds). The value 150.12345 (pounds) is perfectly valid. It should not be truncated to 150.12. Or another, "Length" (expressed in terms of Feet): 17.0625 (that's 17 feet, 1 inch) - should not be morphed into 17.06.

To work around this, developers currently either have to override a <GridColumn>'s <EditorTemplate> and place a <TelerikNumericTextBox> element bound to the same property that the <GridColumn> is, and explictly set the Decimals property themselves.

Or what I have found is a better workaround, although not desirable to have to do this at all, is to put this kind of code snippet in the Program.cs file, right after the line var app = builder.Build();

app.UseRequestLocalization(action =>
{
   var currentCulture = CultureInfo.CurrentCulture.Clone() as CultureInfo;
   currentCulture!.NumberFormat.NumberDecimalDigits = 10; // for example, to allow this many decimal places in everything numeric
   var cultures = new List<CultureInfo>() { currentCulture };
   action.SupportedCultures = cultures;
});

Please remove the default value for the Decimals property being tied to the culture. It should just allow as many decimal places as a normal float or double would allow for its precision. Perhaps just allow a developer to set it and honor that, but if not set, basically let it be unlimited, just like the number of digits to the left of the decimal point.

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
3 comments
ADMIN
Dimo
Posted on: 04 Aug 2023 07:42

Hi Jack,

The default Decimals value can depend on:

  • arbitrary magic number that we determine ourselves
  • regional settings
  • or we can leave the parameter without a default value

We believe the current state makes the most sense and there are different ways to customize the component behavior. I do agree that not everything is dollars and cents, but it also matters what do users edit most often.

I pinged our devs with the idea to remove the default Decimals value from NumericTextBoxes that do NOT have a decimal value, but that sounded too heuristic and unpredictable in terms of component stability and developer expectations.

Since you are talking about editors in Grid, I am linking this item to an existing one, which will allow you to configure such scenarios more easily.

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Jack
Posted on: 29 Jul 2023 14:34

P.S. This issue presents itself in TelerikGrid components, particularly when using auto generated columns where the developer isn't explicitly creating TelerikNumericTextBox component instances themselves. It does it automatically based on the generated GridColumn and the type of property it is bound to.

So the answer is not for everyone to simply set the Decimals property on every instance - we are not even creating these instances manually.

Jack
Posted on: 28 Jul 2023 22:46
Oops. 17.0625 is not 17 feet 1 inch, it's 17 feet and a sixteenth of a foot. Pretend I said 17.083333333 (close enough to 17 feet, 1 inch). Still, the argument is the same.