-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NumericUpDown control changes #5981
Conversation
Thanks for the contribution! |
@maxkatz6 probably we have something in MathUtils class that can deal with this kind of stuff? |
@danwalmsley I don't see anything that can help us in https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Utilities/MathUtilities.cs But I am not sure, do we need to Round here or Truncate? |
Internally, the backing type should probably be Note: Switching to decimal is especially important for currency input scenarios where precision is mandatory in the math. This shouldn't just be "hidden" using rounding techniques. |
Yes, that was how I approached it. But it makes more sense to change the backing type to decimal considering currency input. I'm happy to make the changes for decimal backing type. or Adding a new DecimalValue. Sorry I'm new to this, should I close out this PR? |
A few other comments:
Edit It seems NumericUpDown has most of the pieces for doing formatting correctly already: The decimal backing type change plus adding the |
…d ThrowCannotBeGreaterThanException to accept generics as it displays the values only.
@puppetsw technically switching from double to decimal is a breaking changes, that's why build is failing. You need to follow this tutorial to allow that https://stu.dev/check-for-breaking-changes-with-apicompat/ . |
I've made type changes to the NumericUpDown class and event class. Added a NumberFormat property and have also set it through the CultureInfo to keep backwards compatibility. Marked CultureInfo as Obsolete. I also added a new Clamp method to the MathUtilities. |
Core team doesn't really like anyone marking things as obsolete unless you run in past them first. @danwalmsley will need to buy in on this. |
/// <param name="min">The minimum value.</param> | ||
/// <param name="max">The maximum value.</param> | ||
/// <returns>The clamped value.</returns> | ||
public static decimal Clamp(decimal val, decimal min, decimal max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with System.Math.Clamp(Decimal, Decimal, Decimal)
? https://docs.microsoft.com/en-us/dotnet/api/system.math.clamp?view=net-5.0#System_Math_Clamp_System_Decimal_System_Decimal_System_Decimal_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not available in netstandard 2.0
I've not really been following this PR - are we agreed that it's a good idea to break the API and change the values from |
@grokys personally I agree with that. Also it seems to be binary breaking change only, since both xaml and c# implicitly convert from decimal to double and in other way. |
Ok, I'm fine with accepting your judgement on that ;) Looks good to me, but I'll leave the final review to you. |
# Conflicts: # src/Avalonia.Controls/ApiCompatBaseline.txt
Updated samples and ApiCompat. Thanks! |
What does the pull request do?
Attempts to issue #5318 fix by adding a property for decimal places to the control.
What is the current behavior?
When the NumericUpDown control is at a value of 5.6 and Increment is 0.01, if adjusted up, it will appear as 0.570000000000000001 instead of 0.57
What is the updated/expected behavior with this PR?
The value should be 0.57
How was the solution implemented (if it's not obvious)?
Changing the backing type for NumericUpDown to decimal breaks contracts.
Checklist
Breaking changes
Changing the backing type for NumericUpDown to decimal breaks contracts.
Obsoletions / Deprecations
CultureInfo property is obsolete @AvaloniaUI/core
Users should use NumberFormat instead.
Fixed issues
Fixes #5318