locked
round vs truncate sql vs c# RRS feed

  • Question

  • I have a numeric column in a table defined as numeric (9,4)

    When I insert a higher precision floating point number - the number ends up being rounded to the nearest 4th decimal digit - which is as predicted.

    However  - when using a C# application that creates a "row" in memory and then uses sqlBulkInsert to enter the rows - the number that was written to that column gets the value truncated to the 4th digit - and not rounded, causing a loss of precision.

    What's the best way to not have that happen?

    • Moved by Bob Beauchemin Tuesday, March 26, 2013 7:02 PM Moved to the forum for SqlBulkInsert for best response
    Tuesday, March 26, 2013 4:14 PM

Answers

  • Hi,

    From CLR type to SQL Server data type, some type mappings may result in overflow or data loss exceptions while translating to or from the database. Please refer to this page: http://msdn.microsoft.com/en-us/library/bb386947.aspx

    Please check the CLR type you use in your code.

    • Proposed as answer by Papy Normand Saturday, April 6, 2013 8:56 AM
    • Marked as answer by Mike Feng Tuesday, April 9, 2013 4:10 PM
    Thursday, March 28, 2013 7:51 AM

All replies