feat(Calculator): format large numbers with locale-aware thousands separators#47001
feat(Calculator): format large numbers with locale-aware thousands separators#47001SAY-5 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Calculator results like 1000000 now display as 1,000,000 (or the locale equivalent). Uses the N format specifier with the same number of decimal places as the raw result, so 3.14 stays 3.14 but 1000000 becomes 1,000,000. Fixes microsoft#40203
|
This is seriously flawed, so I'm closing it. After an initial review, here are some findings:
return new ListItem(new CopyTextCommand(decimalResult))(Line 130) This results in the formatted value, e.g. "1,234,567.89" being stored for copying, which will likely break every programmatic use case, such as pasting into spreadsheet formulas, code, other calculators etc.
var result = FormatWithSeparators(roundedResult.Value, outputCulture);
...
var saveCommand = new SaveCommand(result);The core issue with the PR is that you're conflating the display formatting with the data value itself. The two need to be strictly separated, and the formatted value should never pollute the rest of the system. I don't believe the work has been tested sufficiently and no proof of testing was submitted. For reference, PowerToys Run correctly separates Finally, please note that an issue with the "Help Wanted" label doesn't mean that you don't need to follow the contributor guidelines. PR work should be pre-agreed. |
|
Fair criticism. I was conflating the display value with the data value. The formatted string leaked into TextToSuggest, CopyCommand, and SaveCommand, breaking copy-paste and saved expression resubmission. The fix needed to only change the Title while leaving the underlying data untouched, like how PowerToys Run separates Title from QueryTextDisplay. Thanks for the detailed breakdown. |
Summary of the Pull Request
Calculator results for large numbers (e.g. 1000000) now display with thousands separators (e.g. 1,000,000) using the user's locale. Small numbers and decimals keep their existing formatting.
The approach: detect how many decimal places the raw result has, then apply the
Nformat specifier with that count. This preserves the original precision while adding separators to the integer part.Before:
1000000/3.14159After:
1,000,000/3.14159PR Checklist