Skip to content
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

Reduce default NumberBox precision to 6 digits #7851

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dev/NumberBox/NumberBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ void NumberBox::OnApplyTemplate()

m_isEnabledChangedRevoker = IsEnabledChanged(winrt::auto_revoke, { this, &NumberBox::OnIsEnabledChanged });

// .NET rounds to 12 significant digits when displaying doubles, so we will do the same.
m_displayRounder.SignificantDigits(12);
// printf() defaults to 6 digits. 6 digits are sufficient for most
// users under most circumstances, while simultaneously avoiding most
// rounding errors for instance during double/float conversion.
m_displayRounder.Increment(1e-6);

UpdateSpinButtonPlacement();
UpdateSpinButtonEnabled();
Expand Down
2 changes: 1 addition & 1 deletion dev/NumberBox/NumberBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class NumberBox :
bool m_valueUpdating{ false };
bool m_textUpdating{ false };

winrt::SignificantDigitsNumberRounder m_displayRounder{};
winrt::IncrementNumberRounder m_displayRounder{};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially didn't consider how this would work with >1 integer digit. Switching to a IncrementNumberRounder ensures that it always formats it with 6 fractional digits no matter how many integer digits it has.


tracker_ref<winrt::TextBox> m_textBox{ this };
tracker_ref<winrt::ContentPresenter> m_headerPresenter{ this };
Expand Down