Skip to content

Commit 190e0e1

Browse files
committed
Fix 'German' number formatting
1 parent 103d383 commit 190e0e1

File tree

1 file changed

+5
-7
lines changed
  • Plugins/Flow.Launcher.Plugin.Calculator

1 file changed

+5
-7
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private string NormalizeNumber(string numberStr)
139139
{
140140
var culture = CultureInfo.CurrentCulture;
141141
var groupSep = culture.NumberFormat.NumberGroupSeparator;
142+
var decimalSep = culture.NumberFormat.NumberDecimalSeparator;
142143

143144
// If the string contains the group separator, check if it's used correctly.
144145
if (!string.IsNullOrEmpty(groupSep) && numberStr.Contains(groupSep))
@@ -164,14 +165,11 @@ private string NormalizeNumber(string numberStr)
164165
}
165166
}
166167

167-
// At this point, any group separators are in valid positions (or there are none).
168-
// We can safely parse with the user's culture.
169-
if (decimal.TryParse(numberStr, NumberStyles.Any, culture, out var number))
170-
{
171-
return number.ToString(CultureInfo.InvariantCulture);
172-
}
168+
// If validation passes, we can assume the separators are used correctly for numbers.
169+
string processedStr = numberStr.Replace(groupSep, "");
170+
processedStr = processedStr.Replace(decimalSep, ".");
173171

174-
return numberStr;
172+
return processedStr;
175173
}
176174

177175
private string FormatResult(decimal roundedResult)

0 commit comments

Comments
 (0)