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



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

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.