Format text with leading zero's

fredp1
Member Posts: 86
Hi
I have a field on a report that is text that I want to have leading zero's.
The text is always a number and I want it be be a maximun of 3 charaters.
e.g
if the text = 4, it should print/display 004
if the text = 52, it should print/display 052
if the text = 152, it should print/display 152
If tried FORMAT(qtytext,0,'<TEXT,3><Filler Character,0>') but it adds the zero to the end.
How do I get it to have leading zero's
Thanks
I have a field on a report that is text that I want to have leading zero's.
The text is always a number and I want it be be a maximun of 3 charaters.
e.g
if the text = 4, it should print/display 004
if the text = 52, it should print/display 052
if the text = 152, it should print/display 152
If tried FORMAT(qtytext,0,'<TEXT,3><Filler Character,0>') but it adds the zero to the end.
How do I get it to have leading zero's
Thanks
0
Answers
-
Hi Fred,
you could try this.Text := PADSTR('',3 - strlen(Text),'0') + Text;
Albert0 -
Hi,
It worked a treat! Thanks...
If i didn't want a blank/zero value to be formated as 000, would i do something like this in a Report Sourceexpr?
if text='', then text else PADSTR('',3 - STRLEN(Text,'0') +text;0 -
What's wrong with?
IF tekst <> '' THEN PADSTR(...
0 -
Hi,
You could create a function in your report and use that function as the SourceExpr.MyFunction(Var Text) IF Text <> '' THEN Text := PADSTR('',MAXSTRLEN(Text) - STRLEN(Text),'0') + Text;
SourceExpr MyFunction(Text)
Albert0 -
I don't think that will work. You need an exit value in your function:
MyFunction(Text) : Text[1024] IF Text <> '' THEN EXIT(PADSTR('',MAXSTRLEN(Text) - STRLEN(Text),'0') + Text);
Reijer Molenaar
Object Manager0 -
Thanks to everyone that replied.
All suggestions were great!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions