I would like to know if its possible to convert negative and positive strings to use an specific format, with a line of code.

"-1.80" into "-18.00"

or

"1.80" into "18.00"

有帮助吗?

解决方案

You need to parse the string into a numeric datatype and then multiply this by ten and format this data type:

    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)

This will work with both negative and positive numbers

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top