× 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.



I went to http://archive.midrange.com   I searched for atof and found this among
many replies:

Subject: Re: Floating Point Question
     From: dhandy@xxxxxxxxxxx (Douglas Handy)
     Date: Wed, 24 May 2000 10:06:22 -0400

<SNIP>

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.

<SNIP>

I think the most important thing to look at is that you have the prototype 
declared correctly.

Regards,

Jim Langston

Colin Thorpe wrote:

> Hi all,
>
> I am trying to take a character field (10A) containing something like
> 123.45bbbbb,
> And move it into a numeric field (12,2) 0000000123.45.
>
> The character field may or may not contain a decimal point.
> Therefore its value could be from  .01 ==> 9999999999
>
> Some time ago the C function ATOL was mentioned by Hans.
>
> I'm using V3R7 and managed to get his example working fine.
>
> Unfortunately this only returns the integer part of the value.
>
> I also tried ATOF but I'm not sure what the resulting value means.  2235.14
> = 1079246848 ?
>
> I can solve this problem using data structures and selects but I'm looking
> for an elegant ILE solution.
>
> Any help will be greatly appreciated.
>
> Thanks in advance
>
> Colin
>
> +---
> | 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
> +---

+---
| 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 thread ...

Replies:

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.