Skip to content

Commit 76f834f

Browse files
committed
PR review changes
1 parent 161c546 commit 76f834f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,18 @@ private string NormalizeNumber(string numberStr, ParsingContext context)
219219
return numberStr;
220220
}
221221

222-
223222
private string FormatResult(decimal roundedResult, ParsingContext context)
224223
{
225224
string decimalSeparator = context.InputDecimalSeparator ?? GetDecimalSeparator();
226-
string groupSeparator = decimalSeparator == dot ? comma : dot;
225+
string groupSeparator = GetGroupSeparator(decimalSeparator);
227226

228227
string resultStr = roundedResult.ToString(CultureInfo.InvariantCulture);
229228

230229
string[] parts = resultStr.Split('.');
231230
string integerPart = parts[0];
232231
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;
233232

234-
if (context.InputUsesGroupSeparators)
233+
if (context.InputUsesGroupSeparators && integerPart.Length > 3)
235234
{
236235
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
237236
}
@@ -244,9 +243,17 @@ private string FormatResult(decimal roundedResult, ParsingContext context)
244243
return integerPart;
245244
}
246245

246+
private string GetGroupSeparator(string decimalSeparator)
247+
{
248+
// Use system culture's group separator when available and it doesn't conflict
249+
var systemGroupSep = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
250+
return decimalSeparator == systemGroupSep
251+
? (decimalSeparator == dot ? comma : dot)
252+
: systemGroupSep;
253+
}
254+
247255
private bool CanCalculate(Query query)
248256
{
249-
// Don't execute when user only input "e" or "i" keyword
250257
if (query.Search.Length < 2)
251258
{
252259
return false;

Plugins/Flow.Launcher.Plugin.Calculator/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "Calculator",
55
"Description": "Perform mathematical calculations (including hexadecimal values). Use ',' or '.' as thousand separator or decimal place.",
66
"Author": "cxfksword, dcog989",
7-
"Version": "1.1.0",
7+
"Version": "1.0.0",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
1010
"ExecuteFileName": "Flow.Launcher.Plugin.Calculator.dll",

0 commit comments

Comments
 (0)