#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Options

# Conversion of text to decimal

Member Posts: 171
edited 2006-02-15
Dear Friends,

How to convert a text into a decimal value.

N.Sridhar

• Options
Member Posts: 920
Use the EVALUATE function. A description of this can be found in the online help.
Kai Kowalewski
• Options
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
• Options
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
• Options
Member Posts: 171
Hi Friends,

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

Thanks & Regards,

N.Sridhar
• Options
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)
• Options
Member Posts: 171
Thank you very much Luc Van Dyck.

Works Fine.

Thanks & Regards,
N.Sridhar
• Options
Member, Moderator Posts: 9,098
```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!