RadzenNumeric has precision issues #659

Closed
opened 2026-01-29 17:41:06 +00:00 by claunia · 1 comment
Owner

Originally created by @sofiageo on GitHub (Dec 5, 2022).

Describe the bug
RadzenNumeric has precision issues because of how it tries to convert a double value.

To Reproduce
Use a RadzenNumeric with a double value of 266273.2949999999 and a Format of N2 - or C2.

Expected behavior
Expect the value to be rounded to 266273.29 - Instead the value will be rounded to 266273.30

Additional context
You can see the difference in values when you run the following demo:

double num1 = 266273.294999999;
double num2 = 266273.2949999999;
decimal decimal1 = (decimal)Convert.ChangeType(num1, typeof(decimal));
decimal decimal2 = (decimal)Convert.ChangeType(num2, typeof(decimal));
decimal decimal3 = decimal.Parse(num2.ToString("G17"));
Console.WriteLine(decimal1.ToString("N2"));
Console.WriteLine(decimal2.ToString("N2"));
Console.WriteLine(decimal3.ToString("N2"));

I've got the idea for using toString("G17") from this SO question

Originally created by @sofiageo on GitHub (Dec 5, 2022). **Describe the bug** RadzenNumeric has precision issues because of how it tries to convert a double value. **To Reproduce** Use a RadzenNumeric with a double value of 266273.2949999999 and a Format of N2 - or C2. **Expected behavior** Expect the value to be rounded to 266273.29 - Instead the value will be rounded to 266273.30 **Additional context** You can see the difference in values when you run the following demo: ``` double num1 = 266273.294999999; double num2 = 266273.2949999999; decimal decimal1 = (decimal)Convert.ChangeType(num1, typeof(decimal)); decimal decimal2 = (decimal)Convert.ChangeType(num2, typeof(decimal)); decimal decimal3 = decimal.Parse(num2.ToString("G17")); Console.WriteLine(decimal1.ToString("N2")); Console.WriteLine(decimal2.ToString("N2")); Console.WriteLine(decimal3.ToString("N2")); ``` I've got the idea for using toString("G17") from this [SO question](https://stackoverflow.com/a/46568334)
Author
Owner

@akorchev commented on GitHub (May 9, 2023):

Not sure if we can do anything in this regard without breaking the existing implementation. We are currently using Convert.ChangeType.

@akorchev commented on GitHub (May 9, 2023): Not sure if we can do anything in this regard without breaking the existing implementation. We are currently using Convert.ChangeType.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#659