Deleting empty spaces and converting decimals to text(
aari
Member Posts: 7
Hi
i have to write a codeunit that deletes empty spaces from decimals and convert it to a text30
i have to write a codeunit that deletes empty spaces from decimals and convert it to a text30
0
Comments
-
Good luck
0 -
Hi,
I'm presuming that instead of encouragement you are looking for a few hints
Have a look at the DELCHR and FORMAT functions.
gl,
Remco0 -
yeah something like this maybe....
yourtext := FORMAT(yourdecimal); //converts decimal to text
yourtext := DELCHR(yourtext,'=',' '); //deletes blanks from text0 -
-
DenSter wrote:A decimal type variable doesn't have empty spaces.
I was thinking that too 8)0 -
hi
thanks for answering
i have problem that i have to write a codeunit
that converts decimal to text 30
like this if decimal =123456789,12 then it should be 1 234 56789,12 in text
as you see it means that i have to delete third space in integer thousand
and can be run from other objects
I tried some code
Dec:=123456789 ;
//text[1]:=CONVERTSTR(FORMAT(Dec,0,'<Integer Thousand><Decimals>'),',','.');
txtDecimals:=CONVERTSTR(FORMAT(Dec,3,'<Decimals,>'),',','.');
txtThousands:=CONVERTSTR(FORMAT(Dec,0,'<Integer Thousand>'),',','.');
Intstrpos := STRPOS(txtThousands,'''') ;
IF Intstrpos >0 THEN BEGIN
txtEmspacedel:=DELSTR(txtThousands,Intstrpos,1);
txtanswer:=txtEmspacedel+txtDecimals;
MESSAGE(txtanswer)
END
ELSE BEGIN
txtanswer:= txtThousands+txtDecimals ;
MESSAGE(txtanswer);
END;
MESSAGE (text[1]);0 -
Hi aari
if you have
Dec := 123456789,12
then
FORMAT(Dec) wil give 123.456.789,12 (assuming that thousands separator is . and Decimal is , )
so you could do
TextDec := CONVERTSTR(FORMAT(Dec),',',' ');
TextDec := CONVERTSTR(TextDec),'.',' ');
this should result in 123 456 789 12
Albert0 -
thanks Albertvh but i have to eliminate the third space
It should look like 123 456789,120 -
i think i have to use return value in locals to call this codeunit in other objects
,am i right?0 -
Hi aari
Yes you will have to set a return value and also a passed value
I have tested some code and it worksReturnDecimalString(Dec : Decimal) : Text[30] String := FORMAT(Dec); strCommas := DELCHR(String,'=',DELCHR(String,'=',',')); intNoOfLoops := STRLEN(strCommas ); x := 1; String2 := ''; WHILE x <= intNoOfLoops DO BEGIN IF intNoOfLoops = 1 THEN BEGIN IF STRPOS(String,',') > 0 THEN String2 := DELCHR(String,'=',','); END ELSE BEGIN IF x = 1 THEN BEGIN IF STRPOS(String,',') > 0 THEN String2 := COPYSTR(String,1,STRPOS(String,',') - 1) + ' '; END ELSE IF intNoOfLoops - x > 0 THEN String2 := String2 + COPYSTR(String,1,STRPOS(String,',') - 1) + ' ' ELSE String2 := String2 + COPYSTR(String,1,STRPOS(String,',') - 1) + COPYSTR(String,STRPOS(String,',') + 1 ); String := COPYSTR(String,STRPOS(String,',') + 1); END; x := x + 1; END; EXIT(String2);
[Edit]
Variables are as follows
Name DataType Subtype Length
String Text 30
String2 Text 30
OrgString Text 30
strCommas Text 30
intNoOfLoops Integer
x Integer
[End Edit]
Hope this helps (Used some of Waldo's tips)

Albert0 -
i made it like this
txtDecimals:=CONVERTSTR(FORMAT(decInput,0,'<Decimals,3>'),',','.');
txtInteger:=CONVERTSTR(FORMAT(decInput,0,'<Integer>'),',','.');
intstrlen := STRLEN(txtInteger);
IF intstrlen>6 THEN BEGIN
IntIntstr:=intstrlen-5;
txtInteger:= INSSTR(txtInteger,' ',IntIntstr);
txtOut:=txtInteger+txtDecimals;
END
ELSE BEGIN
txtOut:=txtInteger+txtDecimals;
END;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K 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
- 323 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
