Division operation string values using tmap

Six Stars

Division operation string values using tmap

Hi Team,

 

I have two columns which values contains 0(ZERO) both columns are string.

 

Expression: col1/col2

datatype should be float or decimal and load into redshift table(numeric data type)

 

Note: col1 and col2 either or both contains 0 values col1 and col2.

 

How to achieve above scenario.

 

Thanks

shree

 

Eleven Stars

Re: Division operation string values using tmap

(col2!=0)?col1/col2:0

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Eleven Stars

Re: Division operation string values using tmap

http://www.cafeaulait.org/course/week2/43.html

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Forteen Stars TRF
Forteen Stars

Re: Division operation string values using tmap

You need to use equals method to compare string variables, then you can use Float.parseFloat to convert both strings to Float before the division:

 

(row1.col2.equals("0")) ? 0 : Float.parseFloat(row1.col1) / Float.parseFloat(row1.col2)

TRF
Forteen Stars TRF
Forteen Stars

Re: Division operation string values using tmap

@bshree88did this help you? If so, thank's to mark you case as Solved (Kudos also accepted)


TRF