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

Showing Answers 1 - 2 of 2 Answers

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.

  Was this answer useful?  Yes

jyothi

  • Apr 20th, 2006
 

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

  Was this answer useful?  Yes

sangee

  • Nov 29th, 2006
 

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

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

chandu_swe

  • Aug 18th, 2007
 

To change string to decimal we use atoi function.

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions