我需要小数存储到MySQL,它可以有一个不同的precision。因此,我很想知道MySQL的字段类型是绝对等同于.NET的十进制结构,如果有的话。
I need to store decimals into MySQL, which can have a varying precision. Therefore I would be interested to know which MySQL field type is absolutely equivalent to .NET's decimal structure, if any.
我打算使用小巧玲珑作为一个轻量级的ORM。
I plan to use Dapper as a lightweight ORM.
在.NET小数可以引擎盖下不同的数据类型。
The .net decimal can be different datatypes 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.
警告
需要注意的是,根据乔恩斯基特,十进制
可以在很多方面被宣布,但将永远是一个 FLOAT
下油烟机,所有的舍入误差带来,你已经被警告。
请参阅: SQL十进制等效于.NET
Warning
Note that according to Jon Skeet, decimal
can be declared in lots of ways, but will always be a FLOAT
under the hood, with all the rounding errors that brings, you have been warned.
See: SQL decimal equivalent in .NET
如果您分配一个较大的precision MySQL的十进制
占用了更多的空间。
MySQL's DECIMAL
takes up more space if you assign it a larger precision.
这本手册: HTTP ://dev.mysql.com/doc/refman/5.5/en/$p$pcision-math-decimal-changes.html
值在MySQL 5.5 DECIMAL列使用的是包9个十进制数字为4个字节的二进制格式存储。
Values for DECIMAL columns in MySQL 5.5 are stored using a binary format that packs nine decimal digits into 4 bytes.
最大位数为65,9 = 8个字节,一个INT128分。
The largest number of digits is 65, divided by 9 = 8 bytes, an INT128.
上一篇:谷歌Android地图视图视图、地图、谷歌、Android
下一篇:机器人,帮助有simpleframework的PersistenceException机器人、simpleframework、PersistenceException