何时在 sql server 中使用 Money 数据或 Decimal 数据类型来存储成本值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22343185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When to use Money data or Decimal Data type in sql server to store costing values?
提问by user3378215
What is preferable data type to store the costing value ? Money or Decimal whats the programmatic diff bet them? asp.net Data Annotation for asp.net Model for Money data type ?
存储成本计算值的首选数据类型是什么?金钱或十进制什么是程序化的差异赌注?用于货币数据类型的 asp.net 模型的 asp.net 数据注释?
回答by Raging Bull
Decimal
type provides more precision to hold intermediate results to get the results you expect.
Decimal
type 提供更高的精度来保存中间结果以获得您期望的结果。
Disadvantages of money
datatype:
money
数据类型的缺点:
It is proprietary, so porting it is a pain. It is one of the many "Sybase Code Museum" features from decades ago. Remember the early versions of UNIX?
Writing code in dialect when you don't need to make you sound like a hillbilly to people that speak the language. You are better off with DECIMAL(s,p) so you can use a properly sized column.
It does display and formatting in the back end, with commas and dollar signs. That defeats the purpose of a tiered architecture.
The MONEY data type has rounding errors.
它是专有的,所以移植它很痛苦。它是几十年前众多“Sybase 代码博物馆”功能之一。还记得 UNIX 的早期版本吗?
当您不需要让使用方言的人听起来像乡巴佬时,用方言编写代码。您最好使用 DECIMAL(s,p) 以便您可以使用大小合适的列。
它确实在后端显示和格式化,使用逗号和美元符号。这违背了分层架构的目的。
MONEY 数据类型存在舍入错误。
Ref:msdn
参考:msdn
回答by Rahul Tripathi
You should prefer decimal
as money
datatype is not precise.
您应该更喜欢,decimal
因为money
数据类型不精确。
You may also check Performance / Storage Comparisons : MONEY vs. DECIMALby Aaron Bertrand
您还可以查看Aaron Bertrand 的Performance / Storage Comparisons : MONEY vs. DECIMAL