Convert a string to decimal in VB.NET
问题 What will be the easiest way to convert a string to decimal? Input: a = 40000.00- Output will be 40,000.00- I tried to use this code: Dim a as string a = "4000.00-" a = Format$(a, "#,###.##") console.writeline (a) 回答1: Use Decimal.Parse to convert to decimal number, and then use .ToString("format here") to convert back to a string. Dim aAsDecimal as Decimal = Decimal.Parse(a).ToString("format here") Last resort approach (not recommended): string s = (aAsDecimal <0) ? Math.Abs(aAsDecimal)