# What is the function you would use to transfer a string into a decimal?

#### Ashim Dutta

• Jul 10th, 2005

In this case no specific function is required if the size of the string and decimal is same. Just use decimal cast with the size in the transform function and will suffice. For example, if the source field is defined as string(8) and the destination as decimal(8) then (say the field name is field1).

out.field :: (decimal(8)) in.field

If the destination field size is lesser than the input then use of string_substring function can be used likie the following.
say destination field is decimal(5).

out.field :: (decimal(5))string_lrtrim(string_substring(in.field,1,5)) /* string_lrtrim used to trim leading and trailing spaces */

Hope this solution works.

#### jyothi

• Apr 20th, 2006

i want a clear explanaion for this question .can anyone help me?

#### sangee

• Nov 29th, 2006

i think we can go for decimal strip function in our transform .we can also do by using casting function.

#### mukund

• Dec 7th, 2006

Hey,

use ""reinterpret_as" function to convert string to decimal,or decimal to string.

syntax:  To convert decimal onto string

reinterpret_as(ebcdic string(13),(ebcdic decimal(13))(in.cust_amount))

Cheers,

Mukund

#### chandu_swe

• Aug 18th, 2007

To change string to decimal we use atoi function.

#### Subhash_mahato Profile Answers by Subhash_mahato

• Dec 8th, 2009

You can go for a simple typecasting from string to decimal but before that you need to check if the string can be converted to decimal or not.

Suppose the string has a junk value say "123abs" (alpha-numeric) then most of the functions will fail.

In that case you need to check the validity of the data and decimalstrip is good function for conversion.

#### abmaahi Profile Answers by abmaahi Questions by abmaahi

• Mar 29th, 2010

#### venkat_jaksani Profile Answers by venkat_jaksani Questions by venkat_jaksani

• Jun 17th, 2010

If string conains the alphanuemica data the decimal-strip will remove the alpanumeric data but the decimal(length) will not remove alphanumeric data.Please let me know If I am wrong.