Weird truncation happens when convert DT_R8 to DT_CY
Hi, I have been working on truncation issue from DT_R8 to DT_CY. Here are steps to reproduce it. 1. Prepare some mock data(DT_R8) by BIDS, such as 25.492452, 23.11795 which scale is longer than 4. 2. create a table which column type is money, and load the data from step 1 into this table. expected result: 25.492452 will be rounded to be 25.4925 and loaded into destination table. 23.11795 will be rounded to be 23.118 and loaded into destination table. real results 25.492452 is rounded to be 25.4925 and loaded into destination table. 23.11795 is truncated to be 23.1179 and loaded into destination table. This is really weird. I found a general rule for this issue. When there are 6 digits(or more) after decimal point, if the fifth number is bigger than 5, then normal round happens. When there are 5 digit after decimal point, whatever the fifth number is, the fifth number willbe truncated. Is this a bug? Thanks in advance. Jackie
March 23rd, 2011 11:23am

Hi Jackie, I couldn't reproduce this result. In SSIS2005 the output is as expected. Val Derived Column 2 25.492452 25.4925 23.11795 23.118
Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2011 11:55am

Hi Jackie, I couldn't reproduce this result. In SSIS2005 the output is as expected. Val Derived Column 2 25.492452 25.4925 23.11795 23.118 I have checked in SSIS 2008.. and check the results.. it same as Christa's results.. A CY_A 25.492452 25.4925 23.11795 23.118 Let us TRY this | My Blog :: http://quest4gen.blogspot.com/
March 23rd, 2011 12:03pm

Thanks for your reply. I am using BIDS 2008. when I said "destination table", I means loaded the data into the real table(data from data flow--> destination table with money type column) in database rather than derived column. Thanks Jackie
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 5:42am

Other people also met this issue. The general rule for this issue is that: When there are 6 digits(or more) after decimal point, if the sixth number is even number, then normal round happens; if the sixth number is odd number then the fifth number will be truncated no matter the fifth number is bigger than 5 or not; when there are 5 digit after decimal point, whatever the fifth number is, the fifth number will be truncated. Thanks Jackie
March 24th, 2011 6:23am

But you can fix it, if you do the Conversion in SSIS. As ETL vs ELTL and I showed it will work fine there .
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 11:22am

Yes, I can fix it by other ways like you said. But I think this is still an issue. Thanks for your response. Jackie.
March 24th, 2011 1:17pm

The issue is likely that a DT_R8 is a floating point number. As such it is not an exact representation of a decimal number. Just because the closest decimal representation seems to indicate that it should round a certain way doesn't necessarily mean that it will. 23.11795 as stored by a floating point may be slightly more or less than that decimal number. You're expecting the last "5" to cause it to round "up"... but the actual storage of that number may be closer to 23.11794999999... in which case it will round down. You can't count on floating point numbers to accurately store decimal numbers. Period. You should use a DECIMAL type... or whatever "integral" data type is closest in the system you're using. Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
March 26th, 2011 1:28am

Thanks for your reply. I think this is the answer i need. thanks again! Jackie
March 28th, 2011 11:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics