问题
I have a big problem, I used this codes to generate the number to currency,
Dim reg = New Regex("\d+")
Dim str As String = dZ.Rows(y).Item(14).ToString().Replace(",", ""). _
Replace(".00", "").Replace("$", "").Trim
Dim match = reg.Match(str)
If match.Success Then
str = reg.Replace(str, Decimal.Parse(match.Value).ToString("C"))
End If
yes it works, but what if my amount is:
1,900.50 POC
回答1:
kelvzy your solution is not very flexible. I will suggest my solution:
string cellValue = dZ.Rows[y][14];
string cleanedCellValue = Regex.Replace(s, @"\s[^\d.,]+", "");
//this will replace everything after the last digit
string decimalValue = Convert.ToDecimal(cleanedCellValue, CultureInfo.InvariantCulture);
string str = decimalValue.ToString("C");
This solution will work, when each cell uses comma as thousand separator, dot as decimal separator and any symbols as currency symbol.
In other case give me please more examples
来源:https://stackoverflow.com/questions/14065466/regex-error-in-currency