Deleting empty spaces and converting decimals to text(

aariaari Member Posts: 7
Hi
i have to write a codeunit that deletes empty spaces from decimals and convert it to a text30

Comments

  • MbadMbad Member Posts: 344
    Good luck :)
  • remco_rauschremco_rausch Member Posts: 68
    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,

    Remco
  • SavatageSavatage Member Posts: 7,142
    yeah something like this maybe....

    yourtext := FORMAT(yourdecimal); //converts decimal to text

    yourtext := DELCHR(yourtext,'=',' '); //deletes blanks from text
  • DenSterDenSter Member Posts: 8,307
    A decimal type variable doesn't have empty spaces.
  • SavatageSavatage Member Posts: 7,142
    DenSter wrote:
    A decimal type variable doesn't have empty spaces.

    I was thinking that too 8)
  • aariaari Member Posts: 7
    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]);
  • AlbertvhAlbertvh Member Posts: 516
    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


    Albert
  • aariaari Member Posts: 7
    thanks Albertvh but i have to eliminate the third space
    It should look like 123 456789,12
  • aariaari Member Posts: 7
    i think i have to use return value in locals to call this codeunit in other objects
    ,am i right?
  • AlbertvhAlbertvh Member Posts: 516
    Hi aari

    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]

    Hope this helps (Used some of Waldo's tips) :wink::D

    Albert
  • aariaari Member Posts: 7
    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;
Sign In or Register to comment.