Thursday, December 18, 2008

SSIS runtime de-round Numbers

Issue: I have very strange issue with package that transofm data from excel file to text file, the issue that if there's a value in the excel with decimal point ends with .12345 it transformed to text file to .123449999999998. actuall all the sequence numbers less than or equal 5 drop the same issue.
for examble if we have the below value in the excel:
22.12345 it transfomed to 22.123449999999998 in the text file, i put i dataviewer after the excel data source and everything seems alright, the data type of the source columns are double precision.

Cause: Unknown, i communicated with one developer from SSIS team and he tried to troupleshoot the problem with me, but the cause is still unknows.

Wrok Around solution:


put a data conversion before the destination, and convert the type to decimal with only 5 scale.


1 comment:

  1. This is because some decimal numbers cannot be fully reprsented in binary like:

    decimal = 0.2
    0.2 * 2 = 0.4 --> 0
    0.4 * 2 = 0.8 --> 0
    0.8 * 2 = 1.6 --> 1
    0.6 * 2 = 1.2 --> 1
    0.2 * 2
    0.00110011001100110011.......

    decimal 0.3
    0.3 * 2 = 0.6 --> 0
    0.6 * 2 = 1.2 --> 1
    0.2 * 2 = 0.4 --> 0
    0.4 * 2 = 0.8 --> 0
    0.0100110011001100110011....

    while other numbers can be fully reprsented like:

    decimal : 0.25
    0.25 * 2 = 0.5 --> 0
    0.5 * 2 = 1 --> 1
    0.01 exactly

    so when a not-fully reprsented number is stored in the machine, and as it will be stored as a binary number whatever the machine is, it may or may not be converted to decimal correctly when we call it back depending on the reprsentation used for storing the binary number(IBM mesh 3aref a, IEEE mesh 3aref kam) along with the algorithm used for rounding back the number to a decimal

    ReplyDelete