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]);
Yes you will have to set a return value and also a passed value
I have tested some code and it works
ReturnDecimalString(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]
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;
Comments
I'm presuming that instead of encouragement you are looking for a few hints
Have a look at the DELCHR and FORMAT functions.
gl,
Remco
yourtext := FORMAT(yourdecimal); //converts decimal to text
yourtext := DELCHR(yourtext,'=',' '); //deletes blanks from text
http://www.BiloBeauty.com
http://www.autismspeaks.org
RIS Plus, LLC
I was thinking that too 8)
http://www.BiloBeauty.com
http://www.autismspeaks.org
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]);
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
Albert
It should look like 123 456789,12
,am i right?
Yes you will have to set a return value and also a passed value
I have tested some code and it works
[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)
Albert
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;