我想知道是否有可能将负字符串和正字符串转换为使用特定格式,并使用一行代码。
" -1.80"进入" -18.00"
或
" 1.80"进入" 18.00"
答案 0 :(得分:3)
您需要将字符串解析为数值数据类型,然后将其乘以10并格式化此数据类型:
Dim stringValue As String = "-1.80"
Dim doubleValue As Double
Dim outputString As String
If Double.TryParse(stringValue, doubleValue) Then
outputString = (doubleValue * 10).ToString("0.00")
Else
Throw New Exception("Value could not be parsed")
End If
Debug.WriteLine(outputString)
这将适用于正数和正数