What is the best definition of a field for storing a .NET decimal number in MySQL?

I need to store decimal places in MySQL, which can have different precision. Therefore, I would be interested to know what type of MySQL field is absolutely equivalent to the .NET decimal structure, if any.

I plan to use Dapper as a lightweight ORM.

+2
source share
1 answer

. Decimal .net can be different types of data under the hood.

.net formats MySQL ---------------------------------------------------- Decimal(Double) Float Decimal(Int32) DECIMAL Decimal(Int32()) DECIMAL Decimal(Int64) DECIMAL Decimal(Single) DECIMAL Decimal(UInt32) DECIMAL Decimal(UInt64) DECIMAL Decimal(Int32, Int32, Int32, Boolean, Byte) DECIMAL //This is really a UINT96. 

Attention
Please note that, according to John Skeet, decimal can be declared in many ways, but there will always be FLOAT under the hood, while all rounding errors bring, you were warned.
See the decimal equivalent of SQL in .NET

MySQL decimal takes up more space if you give it greater precision.

From the manual: http://dev.mysql.com/doc/refman/5.5/en/precision-math-decimal-changes.html

Values ​​for DECIMAL columns in MySQL 5.5 are stored using a binary format that packs nine decimal digits into 4 bytes.

The maximum number of digits is 65 divided by 9 = 8 bytes, INT128.

+6
source

Source: https://habr.com/ru/post/898764/


All Articles