Adding leading Zeros to a number

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Chandima
Posts: 2
Joined: Wed Sep 06, 2017 4:34 pm

Adding leading Zeros to a number

Post by Chandima »

Hi,
I'm new to Lansa. Can someone help on how to format a string to have leading zeros.
e.g.
34 = 000034
434 = 000434
Thanks
Chandima
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Adding leading Zeros to a number

Post by Stewart Marshall »

Hi Chandima

Here's a simple webpage with a number entry field.

The number is converted to a string and then right adjusted to a specific length. Zero is then used as the pad character to replace any spaces.

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(616) Width(888)

Define_Com Class(#xDemoNumber.Visual) Name(#Number) DisplayPosition(1) Left(24) Parent(#COM_OWNER) TabPosition(1) Top(16) Height(25)
Define_Com Class(#PRIM_LABL) Name(#FormattedNumber) Caption('Formatted Number') DisplayPosition(2) Ellipses(Word) Height(25) Left(336) Parent(#COM_OWNER) TabPosition(2) TabStop(False) Top(14) VerticalAlignment(Center) Width(233)

Evtroutine Handling(#Number.Changed)

#FormattedNumber := #Number.AsString.RightAdjust( 6 "0" )

Endroutine

End_Com
Regards
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
Post Reply