Page 1 of 1

V15: Hiding zeros at the end of numeric field's decimal.

Posted: Wed Feb 02, 2022 1:56 pm
by Rieko Saitoh
Hi all,

If the last few digits in a numeric field is zero, I would like to hide that zero. And I would like to implement it with a numeric field, not a character field. I've tried a few editing options and it seems that decimal zeros are always visible.
I did the following test.

Field definition:
signed(15,5) edit option 2

Value setting:
#hl202042fld := 1
#hl202042fld := 1.2
#hl202042fld := 1.25

Code: Select all

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(247) Clientheight(190) Componentversion(2) Left(1224) Top(370) Layoutmanager(#Layout1)

Define_Com Class(#PRIM_TBLO) Name(#Layout1)
Define_Com Class(#PRIM_TBLO.Row) Name(#Layout1Row1) Displayposition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Column) Name(#Layout1Column1) Displayposition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Item) Name(#Layout1Item1) Alignment(TopCenter) Column(#Layout1Column1) Manage(#Grid1) Parent(#Layout1) Row(#Layout1Row1)
Define_Com Class(#PRIM_GRID) Name(#Grid1) Captionnoblanklines(True) Columnscroll(False) Componentversion(1) Displayposition(1) Left(0) Parent(#COM_OWNER) Showselection(True) Showselectionhilight(False) Showsortarrow(True) Tabposition(1) Top(0) Height(190) Width(247) Rowheight(36) Columnbuttonheight(30)
Define_Com Class(#PRIM_GDCL) Name(#GridColumn1) Displayposition(1) Parent(#Grid1) Source(#hl202042fld) Width(92)

Evtroutine Handling(#com_owner.CreateInstance)
Set Com(#com_owner) Caption(*component_desc)
Endroutine

Evtroutine Handling(#COM_OWNER.Initialize) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Clr_List Named(#Grid1)
#hl202042fld := 1
Add_Entry To_List(#Grid1)
#hl202042fld := 1.2
Add_Entry To_List(#Grid1)
#hl202042fld := 1.25
Add_Entry To_List(#Grid1)
Endroutine

End_Com
Execution screen:
decimal.png
decimal.png (5.2 KiB) Viewed 9630 times

I would like to display as shown below.
1.00000 →1
1.20000 →1.2
1.25000 →1.25
Does anyone know a good way?

Best regards,
Rieko Saitoh

Re: V15: Hiding zeros at the end of numeric field's decimal.

Posted: Thu Feb 03, 2022 8:39 am
by Dino
as you want to handle that as a number, I cannot find an edit code or edit word that can do the trick as usually one of the goals with numbers is to get then aligned to the right and for that, well you need the same quantity of decimals, hence the extra zeros... your best bet is to present it as a string, the trailing zeros will be removed when you use for example AsDisplayString with BareString_M . If you really want to have the column numeric, you can add a second column with the string, and make the first one with the number not visible.

Code: Select all

Define_Com Class(#PRIM_GDCL) Name(#GridColumn1) Parent(#Grid1) Source(#threedec) Width(92) Visible(False)
Define_Com Class(#PRIM_GDCL) Name(#GridColumn2) DisplayPosition(1) Parent(#Grid1) Source(#STD_TEXTL) Width(92)
....
#std_textl := #hl202042fld.AsDisplayString( BareString_M )
editwords.jpg
editwords.jpg (12.09 KiB) Viewed 9615 times

Re: V15: Hiding zeros at the end of numeric field's decimal.

Posted: Thu Feb 03, 2022 1:43 pm
by Rieko Saitoh
Hi Dino,

Thank you so much for replying to this question.
I will consider to use string fields on the screen. Also, I could learn how to use the AsDisplayString method.
Thank you for your support!!

Best regards,
Rieko Saitoh

Re: V15: Hiding zeros at the end of numeric field's decimal.

Posted: Thu Feb 24, 2022 5:57 am
by atostaine
You could try edit word for LANSA. In RPG if your field is 8,5, try edtwrd(' .0 ')

Sometimes it works in RPG, sometimes it doesn't. 9 digit zip codes are difficult too.