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



Scott,

Yes I know. I was just providing an alternative.

Gary Monnier

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Wednesday, March 02, 2011 12:36 PM
To: RPG programming on the IBM i / System i
Subject: Re: Convert Character to Numeric

Gary,

You can accomplish the same thing in one line of code:

fixedLenNbr = %dec( datafield : 20: 2);



On 3/2/2011 2:25 PM, Monnier, Gary wrote:
Jeff,

So how about using a data structure to do the conversion for you?
Something like the following.


D nbrToMoveDS DS
D fixedLenNbr 20S 2
D fixedLenChar 20A overlay(fixedLenNbr:1)
D char18Value 18A overlay(fixedLenChar:1)
D char2Value 2A overlay(fixedLenChar:*NEXT)

fixedLenNbr = 0;

x = ( %scan('.':datafield:1) - 1 ); // Find decimal position
y = ( 18 - x) + 1;

%subst(char18Value:y:x) = %subst(datafield:1:x);

x = x + 2;

char2Value = %subst(datafield:x:2);

And fixedLenNbr should be 123.45.




-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jeff Young
Sent: Wednesday, March 02, 2011 11:14 AM
To: RPG programming on the IBM i / System i
Subject: Re: Convert Character to Numeric

The data is comming from a data file and is in the format 123.45 with
the
decimal point in the data.

Thanks,


Jeff Young
Sr. Programmer Analyst
IBM -e(logo) server Certified Systems Exper - iSeries Technical
Solutions V5R2
IBM Certified Specialist- e(logo) server i5Series Technical Solutions
Designer V5R3
IBM Certified Specialist- e(logo)server i5Series Technical
Solutions Implementer V5R3









________________________________
From: "Rick.Chevalier@xxxxxxxxxxxxxxx"<Rick.Chevalier@xxxxxxxxxxxxxxx>
To: rpg400-l@xxxxxxxxxxxx
Sent: Wed, March 2, 2011 2:04:07 PM
Subject: RE: Convert Character to Numeric

Jeff,

There are two recent threads that relate to this topic. They should
be in the
archives. One is cvthc not converting all values. I deleted the
other thread
from my folder so I can't get the topic for you right now.

How is the data you are receiving formatted? Signed, packed? I know
it's in a
character field, I'm looking for the representation.

Rick

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Jeff Young
Sent: Wednesday, March 02, 2011 12:48 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Convert Character to Numeric

I have a character field where the number of digits and decimal places
is stored
in a file.
I need to convert this to a fixed length numeric field that is defined
in my
program.
It appears that the %Dec BIF required a literal or a value that is
known at
compile time.
What is the best way to do this?

Thanks,

Jeff Young
Sr. Programmer Analyst



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.