Domanda

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"

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top