StringToDecimal Conversion Error

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
nvalia
Premium Member
Premium Member
Posts: 180
Joined: Thu May 26, 2005 6:44 am

StringToDecimal Conversion Error

Post by nvalia »

Hi,

I am reading "amount" from a fixed width seq file as a Char e.g (2259 or 36153.35) and then the only transformation I do before writting to an Oracle table is do type conversion using StringToDecimal.

For some strange reason it stores these values as 2259.580000000000 and 36153.349999999999 respectively. (oracle data type is number 24,12). The first one is correct where as the second one is incorrect.

any idea why?

Reg,
NV
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

Have you used proper Rtype, like Fix_zeros etc.
nvalia
Premium Member
Premium Member
Posts: 180
Joined: Thu May 26, 2005 6:44 am

Post by nvalia »

NO..Fix_Zero is for decimaltostring conversion..

I have tried doing this conversion in a stage varibale and then used the SV in the derivation..
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The conversion is attempting to give you 12 decimal places. In the second case you are getting rounding errors to an acceptable degree of precision (which you can prevent with coding).

The first one looks like a bug; maybe you need to test for the absence of a decimal place holder and add a decimal place and at least one decimal place digit before converting. For example:

Code: Select all

If Index(InLink.TheString, ".", 1) = 0 Then StringToDecimal(InLink.TheString : ".00") Else StringToDecimal(InLink.TheString)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply