Conversion of text to decimal

sridharsridhar Member Posts: 171
Dear Friends,

How to convert a text into a decimal value.

N.Sridhar

Answers

  • KowaKowa Member Posts: 925
    Use the EVALUATE function. A description of this can be found in the online help.
    Kai Kowalewski
  • sridharsridhar Member Posts: 171
    Hi Friends,

    I used the following code to convert the text into a decimal

    ItemQty (DataType : Decimal)
    ItemAvailability (DateType : Text)
    Check (DataType : Boolean)

    Check := EVALUATE(ItemQty,ItemAvailability);
    MESSAGE('%1 %2',ItemQty,Check);

    I am getting the output as - 0 No

    Thanks & Regards,

    N.Sridhar
  • mjrogersmjrogers Member Posts: 59
    Your coding seems to be correct. If the value of the text variable is however blank then the result will be negative.

    For example:
    ItemQty := 0;
    ItemAvailability := '1';
    
    Check := EVALUATE(ItemQty,ItemAvailability);
    
    MESSAGE(FORMAT(Check)+' '+FORMAT(ItemQty));
    

    Result is:

    Yes 1

    ItemQty := 0;
    ItemAvailability := '';
    
    Check := EVALUATE(ItemQty,ItemAvailability);
    
    MESSAGE(FORMAT(Check)+' '+FORMAT(ItemQty));
    

    Result is:

    No 0

    I've tested this and it's fine.
    TecSA Malaysia

    Those of you who think you know everything are annoying to those of us who do. -
    David Brent
  • sridharsridhar Member Posts: 171
    Hi Friends,

    How to convert the string '(-23)' to a decimal value -23.

    Thanks & Regards,

    N.Sridhar
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    sridhar wrote:
    Hi Friends,

    How to convert the string '(-23)' to a decimal value -23.

    Thanks & Regards,

    N.Sridhar
    txtString := '(-23)';
    EVALUATE(decvalue,CONVERTSTR(txtstring,'()','  '));
    MESSAGE('%1',decvalue);
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • sridharsridhar Member Posts: 171
    Thank you very much Luc Van Dyck.

    Works Fine.

    Thanks & Regards,
    N.Sridhar
  • krikikriki Member, Moderator Posts: 9,118
    txtString := '(-23)';
    EVALUATE(decvalue,CONVERTSTR(txtstring,'()','  '));
    MESSAGE('%1',decvalue);
    
    Or something more general:
    txtString := '(-23aBcDeF)';
    txtCharactersToKeep := '1234567890.,-+';
    EVALUATE(decValue,DELCHR(txtString,'=',DELCHR(txtString,'=',txtCharactersToKeep)));
    MESSAGE('%1',decValue)
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.