|
The way I have done it, if you can not just simply create a DS for it, is to use the atof (Ascii to Float) or atol (Ascii to Long) C APIs. Here is an example using atol which is for integers. Notice the first two lines are commented out, but are your prototype for the atof function. D*atof PR 8F ExtProc('atof') D*String * Value Options(*String) D D atol PR 10I 0 ExtProc('atol') D * Value Options(*String) D Invoice S 11A INZ('12345678901') D InvoiceNo S 11S 0 C Eval InvoiceNo = atol(%Trim(TestInvOrCtr)) Limitations on this are the size of the Long Integer. A Long Integer is 4 bytes (I believe, it might be 8). 1 byte is a word, 2 bytes is an integer, 4 bytes is a long integer. But, on some systems, 2 bytes is a short integer, 4 bytes is an integer and 8 bytes is a long integer. You might have to experiment to find the size. The range for a 4 byte integer is -2,147,483,648 to 2,147,483,647. The range for an 8 byte integer is plenty and will give you your 20 bytes. If the atol will not give you enough bytes, consider breaking up the value into two 10 character strings. Take the atol of the first string (left side, most significant digits) and multiply it by 10^10 or 1,000,000,000 and add the second value of the other right side. Or, declare a data structure as 20 numeric, and subdivide it into 2 other numerics 10 long. Then just plug each side in. Thinking on this, however, you can only use 9 digits. It does not go up to 9,999,999,999 but only 2,147,483,647. So only 9 characters are guaranteed accurate. 2 9 character numbers and a 2 character number maybe. Then again, consider just going through each character of the string and if it is a space put in a 0. Then just read it as a number. ----------------------------------------------------------------------------- Floats can be easier, since a floating value can hold a larger number by far, but can also be harder, since you can loose significant digits without even being aware of it. I believe the largest number of digits a float will hold without loosing precision is 15 places. You 10, 3 is 13 places, so it should fit. Just try the maximum and minimum numbers and a few places inbetween after you build yoru function to test it. Good luck, Regards, Jim Langston There go a few more million brain cells. "Baltus, Kevin" wrote: > > > Hello. I may be asking a basic question but what is the best way to convert >an alpha field into a numeric? In my situation I have a 20-Alpha where the >values are whole numbers. I need to get that whole number into a 10.3 field. > > Any suggestions would be greatly appreciated! Thanks! +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.