precision problem from sequential file to DB2

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
yimwai
Participant
Posts: 46
Joined: Thu Jul 01, 2010 9:34 pm

precision problem from sequential file to DB2

Post by yimwai »

source data:sequential file
source value:2324.6199999999999
destination database: db2
data type :decimal(23,10)

We use float datatype to read the file and transform it to decimal(23,10), then the value in the db is 2324.6201171875
why?
how can i make the db2 value is also 2324.6199999999
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Try making the source data type VarChar or Char, rather than float.

Floating point numbers can not be fully accurately represented in digital computers; you can read about the IEEE 754 standard to understand why this is.

Conversion from string to decimal is far more likely to preserve the actual digits in the number represented in the text file.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
yimwai
Participant
Posts: 46
Joined: Thu Jul 01, 2010 9:34 pm

Post by yimwai »

i use varchar to read the file and use StringtoDecimal Function, partly solve the problem.
but in file there is some data with scientific notation such as 2.34567E-2.
varchar cannot help
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

An exact search here for "scientific notation" turned up a number of matches, many marked as Resolved. Check those out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Perhaps your derivation can include an If..Then..Else test looking for the E and using a different format string for StringToDecimal() function.
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