2015-09-04 31 views
0

所以我有这样的:转换非十进制字符串到特定的十进制数在VB

dim nonDecString as string = "12" 
dim decimalPlaces as integer = 2 //this value can be changed dynamically 

我想是来转换nonDecString有小数位为“12.00”或“12.000”,或“12.00n0 ”。

+3

你真的尝试过什么吗?谷歌搜索'十进制格式vb.net'?请展示你的研究工作。 –

回答

2

您可以使用Decimal.ParseDecimal.ToString

Dim dec As Decimal = Decimal.Parse(nonDecString) 
Dim result = dec.ToString("N" & decimalPlaces) 

阅读:Standard Numeric Format Strings, The numeric ("N") format specifier

的精度约束 小数点后位数的所需数量。如果省略精度说明符,则小数位数 由当前的 NumberFormatInfo.NumberDecimalDigits属性定义。

相关问题