문제

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