Hi,
If you are already on release V5R3 or higher, %TrimR will do the job, after
you converted your numeric value into a character one:
/Free
PrintCharField = %TrimR(%Char(MyNumField): '0');
/End-Free
If you are not yet on release V5R3 you may use the SQL scalar function TRIM
to remove trailing *Zeros from a character string:
C/EXEC SQL
C+ Set :PrintCharField = Trim(Trailing '0' from CHAR(:MyNumField))
C/End-Exec
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [
mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Alan
Gesendet: Monday, July 02, 2007 02:08
An: RPG programming on the AS400 / iSeries
Betreff: Re: Edit out trailing 0's
"Ex: .153000 to print like .153.."
This is an expanded version of how I would do it. My "normal" tendency is to
wrap it all up into a single line (and that is doable) but I've been coming
into thinking that when you break out the steps explicitly it's easier
maintenance for the next guy (and that might be you)...
D nbr s 8p 6 inz(1.153000'
D char s 12a
D zero s 1p 0 inz(*Zero)
D xpsn s 5i 0
// Convert to edited number with trailing zeros...
//
char = %editc(nbr:'P') ;
// Check backwards to find the last character *NE zero...
//
xpsn = %checkr(zero:char) ;
// If xpsn = *Zero, there are no trailing blanks, and we're done //
Otherwise, just convert it to the substring that ends at xpsn, which // will
"automatically" drop the trailing zeros // if idx > *zero ;
char = %subst(char:1:idx) ;
endif ;
tim wrote:
Give this a try:
D d s 8 6 inz(1.153)
D da s 8 inz('1.153000')
/free
da = %XLATE('0':' ':
%editc(d:'O'):
%CHECKR('0':%editc(d:'O'))) ;
As an Amazon Associate we earn from qualifying purchases.