Format decimal text with leading zero's

fredp1
Member Posts: 86
Hi,
I've had a previous thread http://www.mibuso.com/forum/viewtopic.php?f=23&t=36144with great respsonses to the question.
I wanted to display leading zero's in a report for a 3 digit integer, e.g. text =5 display 005, text = 56 display 056, text =145 display 145.
Basically the solution was text := PADSTR('',3 - strlen(Text),'0') + Text;
Now I need to be able do the same thing with a decimal number. i.e. the integer portion is always 3 digits with zero padding any leading digits
e.g. text = 1.46, display 001.45
text =67.123 display 067.123
text = 145.7 display 145.7
I was thinking about the format command or do I need to pull apart the string to separate the integer/decimal.
Can anyone help?
Thanks
I've had a previous thread http://www.mibuso.com/forum/viewtopic.php?f=23&t=36144with great respsonses to the question.
I wanted to display leading zero's in a report for a 3 digit integer, e.g. text =5 display 005, text = 56 display 056, text =145 display 145.
Basically the solution was text := PADSTR('',3 - strlen(Text),'0') + Text;
Now I need to be able do the same thing with a decimal number. i.e. the integer portion is always 3 digits with zero padding any leading digits
e.g. text = 1.46, display 001.45
text =67.123 display 067.123
text = 145.7 display 145.7
I was thinking about the format command or do I need to pull apart the string to separate the integer/decimal.
Can anyone help?
Thanks
0
Answers
-
A variant on your previous solution would be:
Text := PADSTR('', 3 - STRLEN(FORMAT(ROUND(DecimalVar, 1, '<'))), '0') + FORMAT(DecimalVar);
Reijer Molenaar
Object Manager0 -
Hi,
Thanks for the reply, but the decimal variable is a text data type.
The suggestion doesn't work on text fields.
Can it be done?
Thanjs0 -
Temporarily removing the decimals should work. Something like this.
decText := COPYSTR(text,STRPOS(text,decimalSign),STRLEN(text));
text := DELSTR(text,STRPOS(text,decimalSign),STRLEN(text));
text := PADSTR('',3 - strlen(Text),'0') + Text + decText;0 -
Hi,
Thanks for the response... I wan't sure if the Format command could be used or if I had to pull apart the string.
Kind regards
Fred0
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