/// <summary>Converts a percentage string into a decimal or decimal? value.</summary> public object GetReadData(Type targetType, string value, string columnName, int columnIndex, int rowNumber) { if (string.IsNullOrWhiteSpace(value)) { if (targetType.HelpIsNullable()) { return(null); } return(0.0m); } // If there is a percentage sign attempt to handle it; // otherwise, differ to the default converter. int indexOfPercentSign = value.IndexOf("%"); if (indexOfPercentSign != -1) { // Remove the percentage sign value = value.Remove(indexOfPercentSign); } // Assign the decimal object someData = _decimalConverter.GetReadData(targetType, value, columnName, columnIndex, rowNumber); if (someData != null) { return((decimal)someData / 100.0m); } throw new ArgumentException($"The {nameof(CsvConverterPercentage)} converter cannot parse the string " + $"'{value}' as a {targetType.Name} on row number {rowNumber} in " + $"column {columnName} at column index {columnIndex}."); }
/// <summary>Converts a string to an int</summary> public object GetReadData(Type inputType, string value, string columnName, int columnIndex, int rowNumber) { if (string.IsNullOrWhiteSpace(value)) { if (inputType.HelpIsNullable()) { return(null); } return(0); } var number = (decimal)_readDecimalConverter.GetReadData(typeof(decimal), value, columnName, columnIndex, rowNumber); return((int)number); }