I have a string like 5.5kg
or 7.90gram
and I want to get 5.5
or 7.90
as a decimal value. How can I get such result in C# and one more thing that my string will always starts with decimal.
Here is my code that throws an error whenever it will encounter anything except a decimal.
string weight = attributeValue;
if (!string.IsNullOrEmpty(weight))
{
product.Weight = Convert.ToDecimal(attributeValue);
}
else
{
product.Weight = 0.00m;
}