@@ -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 ;
0 commit comments