@@ -219,19 +219,18 @@ private string NormalizeNumber(string numberStr, ParsingContext context)
219
219
return numberStr ;
220
220
}
221
221
222
-
223
222
private string FormatResult ( decimal roundedResult , ParsingContext context )
224
223
{
225
224
string decimalSeparator = context . InputDecimalSeparator ?? GetDecimalSeparator ( ) ;
226
- string groupSeparator = decimalSeparator == dot ? comma : dot ;
225
+ string groupSeparator = GetGroupSeparator ( decimalSeparator ) ;
227
226
228
227
string resultStr = roundedResult . ToString ( CultureInfo . InvariantCulture ) ;
229
228
230
229
string [ ] parts = resultStr . Split ( '.' ) ;
231
230
string integerPart = parts [ 0 ] ;
232
231
string fractionalPart = parts . Length > 1 ? parts [ 1 ] : string . Empty ;
233
232
234
- if ( context . InputUsesGroupSeparators )
233
+ if ( context . InputUsesGroupSeparators && integerPart . Length > 3 )
235
234
{
236
235
integerPart = ThousandGroupRegex . Replace ( integerPart , groupSeparator ) ;
237
236
}
@@ -244,9 +243,17 @@ private string FormatResult(decimal roundedResult, ParsingContext context)
244
243
return integerPart ;
245
244
}
246
245
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
+
247
255
private bool CanCalculate ( Query query )
248
256
{
249
- // Don't execute when user only input "e" or "i" keyword
250
257
if ( query . Search . Length < 2 )
251
258
{
252
259
return false ;
0 commit comments