From 1f64c1cf837ca958ad14dc3eb7887f36220a1ef9 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 11 Mar 2022 17:26:29 +0000 Subject: [PATCH] [PTRun][Calculator]Always accept decimal point (#16980) --- .../NumberTranslator.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/NumberTranslator.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/NumberTranslator.cs index 6fdb639310..234ec707de 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/NumberTranslator.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/NumberTranslator.cs @@ -88,7 +88,14 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator private static Regex GetSplitRegex(CultureInfo culture) { - var splitPattern = $"((?:\\d|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}"; + // HACK: Specifically adding the decimal point here since some people expect that to work everywhere. + // This allows avoiding some unexpected errors users are getting when . is not part of the number representation. + // Users were getting errors where leading zeros were being removed from the decimal part of numbers like 56.0002. + // 56.0002 would be transformed into 56.2 due to it being translated as two different numbers and this would be accepted into the engine. + // Now, even if . is not part of the culture representation, users won't hit this error since the number will + // be passed as is to the calculator engine. + // This shouldn't add any regressions into accepted strings while it will have a behavior the users expect. + var splitPattern = $"((?:\\d|\\.|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}"; if (!string.IsNullOrEmpty(culture.NumberFormat.NumberGroupSeparator)) { splitPattern += $"|{Regex.Escape(culture.NumberFormat.NumberGroupSeparator)}";