Thanks Kevin. I'd been trying a number of solutions for quite a while so I
guess I was starting to lose sight of even the basics. Thanks for refreshing
my brain...

Looks like I might stick with the zoned solution as I'd ideally want to have
a variable whose size is defined at runtime.

Thanks again,
Erik

2009/12/13 Kevin Wright <Kevin.Wright@xxxxxxxxxxxx>

Hi Erik,

dec(31,31) will not hold a value greater than
.9999999999999999999999999999999

You may want to use dec(31,15) say which will hold 16 digits before the
decimal point and 15 digits after the decimal point.

dec(n,p) means a decimal that will hold (n - p) digits before the decimal
point, and p digits after the decimal point.

A search of the C400-L archives should reveal a few instances of this or
similar questions. The fine manual should also give the definition.

Regards,

Kevin Wright

-----Original Message-----
From: Erik Olsson [mailto:erik.eo.olsson@xxxxxxxxx]
Sent: Monday, 14 December 2009 9:39 AM
To: C programming iSeries / AS400
Subject: [C400-L] Casting dynamically to packed decimal


What I'm trying to accomplish is convert a void ptr (that's actually a
packed decimal) to a character representation of the pointed to packed
decimal value.

The natural way for me would be to cast the void ptr to a packed decimal
and
then sprintf the decimal variable. But to do that I need to declare a
decimal variable that can hold any valid decimal values and the compiler
demands that the digits and precision are known at compile time.
Declaring one that holds the maximum values (that is, DEC_DIG and
DEC_PRECISION when using the C++ bcd.h file) and casting the void ptr into
that does not give the right result:

Using static_cast to cast say a dec(7,0) into dec(31, 31) results in
garbage
(1 seems to become 0.00000000000...1) when I sprintf it.
Using cpynv to do the same thing crashes with MCH1210 (Receiver value too
small to hold result.).

This doesn't really make sense to me as a dec(7,0) should fit nicely into a
dec(31,31)?

Using cpynv to convert directly to a zoned decimal works, but I'd really
like to get the same visual result as sprintf-ing a packed decimal, that is
no leading zeroes, a decimal point... that kind of look.

Any suggestions would be most welcome.

Thanks,
Erik
--
--
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.



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