Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/LanguagePrimitives.cs (C#)

Code before:

                // BigInteger is not IConvertible and will throw from ChangeType; we know the value we're after is zero.
                if (resultType == typeof(BigInteger))
                {
                    return BigInteger.Zero;
                }

                // This is not wrapped in a try/catch because it can't fail.
                return System.Convert.ChangeType(value: 0, resultType, CultureInfo.InvariantCulture);
            }

            typeConversion.WriteLine("Converting to integer.");

            try
            {
                if (TryScanNumber(strToConvert, resultType, out object result))
                {
                    return result;
                }

               if (resultType == typeof(BigInteger))
               { 
                    // Adjust NumberStyles to remove AllowHexSpecifier for standard numeric parsing
                    NumberStyles style = NumberStyles.AllowLeadingSign 
                    | NumberStyles.AllowDecimalPoint 
                    | NumberStyles.AllowExponent; 
                    BigInteger parsedValue;
                    
                    if (BigInteger.TryParse(strToConvert, style, NumberFormatInfo.InvariantInfo, out parsedValue))
                    {
                        return parsedValue;
                    }
                    
                    throw new PSInvalidCastException("Failed to convert string to BigInteger.");
                }
                // Fallback conversion for regular numeric types.
                return GetIntegerSystemConverter(resultType).ConvertFrom(strToConvert);
            }
            catch (Exception e)
            {
                // This catch has one extra reason to be generic (Exception e).
                // TypeConverter.ConvertFrom wraps its exceptions in a System.Exception.
                if (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                typeConversion.WriteLine("Exception converting to integer: \"{0}\".", e.Message);
                if (e is FormatException)
                {
                    typeConversion.WriteLine("Converting to integer passing through double.");

Review comment (suggestion):
Since BigInteger is an [integer](https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Globalization/NumberStyles.cs,63) and we want to allow thousands separator I'd consider:
```c#
NumberStyles style = NumberStyles.Integer+NumberStyles.AllowThousands;
```

Code after:

            try
            {
                if (TryScanNumber(strToConvert, resultType, out object result))
                {
                    return result;
                }

               if (resultType == typeof(BigInteger))
               { 
                    NumberStyles style = NumberStyles.Integer | NumberStyles.AllowThousands;
                    
                    return BigInteger.Parse(strToConvert, style, NumberFormatInfo.InvariantInfo);
                }
                // Fallback conversion for regular numeric types.
                return GetIntegerSystemConverter(resultType).ConvertFrom(strToConvert);
            }
            catch (Exception e)
            {
                // This catch has one extra reason to be generic (Exception e).
                // TypeConverter.ConvertFrom wraps its exceptions in a System.Exception.
                if (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                typeConversion.WriteLine("Exception converting to integer: \"{0}\".", e.Message);
                if (e is FormatException)
                {
                    typeConversion.WriteLine("Converting to integer passing through double.");
                    try
                    {
                        return ConvertNumericThroughDouble(strToConvert, resultType);
                    }
                    catch (Exception ex) // swallow non-severe exceptions
                    {
                        typeConversion.WriteLine("Exception converting to integer through double: \"{0}\".", ex.Message);
                    }
                }

                throw new PSInvalidCastException("InvalidCastFromStringToInteger", e,
                    ExtendedTypeSystem.InvalidCastExceptionWithInnerException,
                    strToConvert, resultType.ToString(), e.Message);
            }
        }

        private static object ConvertStringToDecimal(object valueToConvert,
                                                     Type resultType,
                                                     bool recursion,
                                                     PSObject originalValueToConvert,
                                                     IFormatProvider formatProvider,