Search code examples
c#vbablueprism

Convert Data type of a collection from Text to Number


I have a Collection <--(image) which is of datatype text. I need to convert it into datatype of number. Any ideas??. I have already tried using c# code in object studio to clone it and convert it to number data type , apparently its not working. please help me out!! this is the code that i used

Output_Collection = Input_Collection.Clone();
Output_Collection.Columns[0].DataType = typeof(Int32);

foreach (DataRow row in Input_Collection.Rows)
{
    Output_Collection.ImportRow(row);
}

Solution

  • Are your number always going to be numeric and have currency symbol = $? If so, you can use (in C#):

    var dec = decimal.Parse(currencyValue, NumberStyles.Currency|NumberStyles.AllowThousands|NumberStyles.AllowDecimalPoint, new CultureInfo("en-US"));
    

    If your currency symbol is going to vary, it gets more tricky - if you don't know the culture of each number it is probably best to use a regular expression to strip off the currency symbol before attempting to parse the value.