About the automatic rounding of. NET when saving decimal type data to a SQLServer2012 database

Source: Internet
Author: User

Company colleagues asked if I have encountered a decimal type of data warehousing, will automatically take the whole problem (such as 12.3 after the value is 12,12.8 storage after the value is 13, after the automatic rounding automatically rounded);

Before the data to go to the decimal type of data, will automatically rounding the problem; I think it should be the same problem, ask colleagues to set the SqlParameter parameter, set scale=2,precision=18; Similar code is as follows:

var New SqlParameter ("@Money", System.Data.SqlDbType.Decimal);              - ;             2 ;             = Model. Money;

According to the above settings, my colleague said to save to the database or automatic rounding, I was puzzled. There's no way to just go to him. Debug and Trace.

Look at exactly where to take the whole, with a parameter before the storage, the value is not rounded, is the original value, that is, the value of the storage after the automatic rounding. The internet searched the question, did not search the useful answer.

Later look at the structure of the table to know, when the table, the Money field decimal type, did not set the decimal place, every time the storage will be automatically rounded, the field type is changed to decimal (18,2), problem solving.

Add a sentence: true pit ... Write an essay to record the problem of the pit.

About the automatic rounding of. NET when saving decimal type data to a SQLServer2012 database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.