× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Char to numeric conversion question
  • From: boldt@xxxxxxxxxx
  • Date: Tue, 20 Apr 1999 08:12:36 -0400



Scott wrote:
>     2) Assuming you're using a version of RPG that supports floating
>        point you could call the atof function from the ILE C
>        binding directories just by prototyping it and binding in
>        the service prgorams...

Best to keep away from floating point unless you're very
careful.  Unlike decimal representation, float generally
does not represent values exactly.  So, if you give atof
the string "25.02", you may well get back the float value
25.019999 as the answer.  If you're careful, you should
be able to deal with this for relatively small values.
But when you bump into the limits of float precision
(around 16 digits), you can never be sure of those least
significant digits.

As others have suggested, probably the best way is to
search for the decimal point, put the portions of the
string to the left and right of the decimal point into
a character subfield that overlays a zoned numeric
subfield, xlate blanks to zeros, and there you have the
value.  You'll need a bit of extra code to handle possible
leading negative sign as well as to scale the number
depending on the position of the decimal point.  The
important thing is to code this into a procedure.  Finally,
once you have a robust procedure coded, why not make it
public so that others can benefit?

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the RPG/400 Discussion Mailing List!  To submit a new         *
* message, send your mail to "RPG400-L@midrange.com".  To unsubscribe   *
* from this list send email to MAJORDOMO@midrange.com and specify       *
* 'unsubscribe RPG400-L' in the body of your message.  Questions should *
* be directed to the list owner / operator: david@midrange.com          *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.