HP3000-L Archives

February 2010, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tracy Pierce <[log in to unmask]>
Reply To:
Tracy Pierce <[log in to unmask]>
Date:
Fri, 19 Feb 2010 13:11:52 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (71 lines)
this method will work for COBOL PIC S9(x) only.

we were led to believe you're dealing with either COMP-3 (packed decimal) or COMP (binary).

does this mean you've decided your input numbers can be represented as a string of ascii characters?  hope so, because the other two are difficult.

Tracy Pierce

> -----Original Message-----
> From: HP-3000 Systems Discussion [mailto:[log in to unmask]] On Behalf Of Greg
> Terterian
> Sent: Friday, February 19, 2010 10:52 AM
> To: [log in to unmask]
> Subject: RE converting from Cobol comp field to readable format - SOLVED!!! HERE IS
> THE SOLUTION in case if anyone else will be interested
> 
> Public Function ConvertFromCOBOLSignedNumberToDouble(ByVal signedNumber As String,
> ByVal decimalPlaces As Integer) As Double
>         ' COBOL Signed Number Converter
>         Dim codeChar As String
>         Dim convertedNumber As Double
>         Dim codeCharsPositive As String = "{ABCDEFGHI"
>         Dim codeCharsNegative As String = "}JKLMNOPQR"
> 
>         signedNumber = signedNumber.Trim
> 
>         If signedNumber = String.Empty Then
>             Return 0
>         End If
> 
>         codeChar = signedNumber.Substring(signedNumber.Length - 1)
> 
>         If codeCharsPositive.IndexOf(codeChar) > -1 Then
>             ' For Positive Numbers, the last digit is converted from
>             ' "{ABCDEFGHI" to "0123456789" respectively.
> 
>             signedNumber = signedNumber.Substring(0, signedNumber.Length - 1) &
> codeCharsPositive.IndexOf(codeChar)
> 
>             convertedNumber = Convert.ToDouble(signedNumber)
> 
>         ElseIf codeCharsNegative.IndexOf(codeChar) > -1 Then
>             ' For Negative Numbers, the last digit is converted from
>             ' "}JKLMNOPQR" to "0123456789" respectively.
> 
>             signedNumber = signedNumber.Substring(0, signedNumber.Length - 1) &
> codeCharsNegative.IndexOf(codeChar)
> 
>             convertedNumber = -Convert.ToDouble(signedNumber)
> 
>         Else
>             ' Not a COBOL Signed Number, but still apply decimal places
>             convertedNumber = CDbl(signedNumber)
>         End If
> 
>         If decimalPlaces > 0 Then
>             Return convertedNumber / (10 ^ decimalPlaces)
>         Else
>             Return convertedNumber
>         End If
>     End Function
> 
> 
> 
> 
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2