Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting unsigned number

Status
Not open for further replies.

KeyserSoze

Programmer
May 18, 2000
79
0
0
US
I have an unsigned number that is stored in an 13-character format (for COBOL afficionadoes, it's stored as S99999999999V99) in ASCII. I would like a way to take this number and convert it to a readable format with the minus sign placed to the right.

Is this possible without building specialized functions to do it?

Thanks!
 
I'm not 100% sure what you are asking for, or what datatype the value you want to convert is. If you are passing in a string, you can try something like this:
Code:
Dim d As Double = CDbl("-123456.78")
Dim s As String = d.ToString("$#,##0.00+;$#,##0.00-;0")
You can change the format expression as needed. The expression above will take into account positive, neagative and 0 values.

Jim
 
I believe this might be what you are looking for:

Code:
Dim inputStr as String = "-0000000123456"
Dim sign as String = inputStr.Substring(0, 1)
Dim outputStr as String

outputStr = String.Format("{0}.{1}{2}", _
                  inputStr.Substring(1, 11).TrimStart(New Char() = {"0"c}), _
                  inputStr.Substring(11, 2), _
                  IIF(sign = "-", sign, "") _
            ) ' Should return "1234.56-"

I haven't had a chance to test this, however.

Hope it helps!

--Rob
 
Thanks to all that replied.

The problem, I just realized, is a little more complicated. The number was originally on a mainframe in EBCDIC format and translated to ASCII. From the ASCII format, I have to translate the data into the proper value and detect whether or not the number is negative, thus applying a negative sign to it.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top