Deepesh
Deepesh

Reputation: 840

Datatype conversion error in pentaho

Hi I have a table column named "sku" which of type integer and another column "total_sku" which again is of type integer , when I'm trying to calculate the percentage(100 * sku/total_sku) using Calculator step. I'm expecting an integer but its giving me 0.00 , kindly help Thanks in advance.

sku   total_sku   percentage
 23      2115       1.087
 40      2115       1.891

Upvotes: 1

Views: 2046

Answers (2)

Ken Clubok
Ken Clubok

Reputation: 1238

My guess is that the calculator is doing the division before the multiplication, computing 100*(A/B), rather than (100*A)/B. Since you are dealing with integers, it is rounding A/B down to zero, and that is the end of it for you.

The calculator step lets you break a calculation down into multiple smaller components, all within the step. You can even specify which fields created in those substeps should stay in the stream, and which should are temporary values that should be discarded.

So try first doing a calculation such as tempValue = 100*A, then result = tempValue/B. Set Value type to Integer in both steps.

Upvotes: 2

Kaustav Datta
Kaustav Datta

Reputation: 403

In the Calculator step, put 'Value type' as 'Integer'

Upvotes: 0

Related Questions