|
Bill, >In an RPG ILE program, I have a 14-byte alpha Field that contains the >external representation of a floating point value, for example: >+1.2345678E005. How can I take this alpha field and convert it into a >4-byte Floating Point Field (with the value 123456.78 in this example)? Every system has a run-time library of functions used for C programs, regardless of whether or not a C compiler is installed. These functions are callable from RPG IV programs, and can often give premade (and tested) functions instead of writing your own. To use them you just need to prototype the call to the C function and then include the QC2LE binding directory on the compile so it can resolve the prototype. In this case, C has a function called "atof" (alpha to float) which will convert an alpha string in the format you describe to an 8-byte float return value.. You can assign this to a 4-byte float if you wish and RPG will handle the conversion. H bnddir('QC2LE') D atof pr 8f extproc('atof') D ptr_to_char * value options(*string) D char s 10a inz('-123.45') C eval num = atof(%trimr(char)) If num is not a float field, it would be advisable to add half-adjust to the eval to minimize the rounding errors of float to other numeric types. Doug +--- | 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-2025 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.