问题描述
在 SQL Server 中,我们可以将数据写入为 Numeric(15,10)
.. 在 C# 中,它的等价物是什么?
In SQL Server we can write data AS Numeric(15,10)
.. what will the equivalent of this in C#?
我知道 Numeric
的等价物是 Decimal
但是如何表示 Numeric(15,10)
?
I know that Numeric
's equivalent is Decimal
but how to represent Numeric(15,10)
?
推荐答案
没有直接的等价物,因为没有内置的 .NET 类型允许您明确指定精度/小数位数,就我而言我知道.没有像 NUMERIC 这样的固定点类型.
There isn't a direct equivalent, in that there are no built-in .NET types which allow you to specify the precision/scale explicitly as far as I'm aware. There's no fixed-point type like NUMERIC.
decimal
和 double
是 .NET 中常见的浮点类型,decimal
实现了 十进制浮点(如 T-SQL 中的 NUMERIC)和 double
实现 二进制浮点 行为(如 T-SQL 中的 FLOAT 和 REAL).(还有 float
,这是一种较小的二进制浮点类型.)
decimal
and double
are the common floating point types in .NET, with decimal
implementing decimal floating point (like NUMERIC in T-SQL) and double
implementing binary floating point behaviour (like FLOAT and REAL in T-SQL). (There's float
as well, which is a smaller binary floating point type.)
您应该根据要表示的值在 decimal
和 double
之间进行选择 - 我通常认为人造"、人工值(尤其是金钱)) 适用于 decimal
,连续的自然值(例如物理尺寸)适用于 double
.
You should choose between decimal
and double
based on what values you're going to represent - I typically think of "man-made", artificial values (particularly money) as being appropriate for decimal
, and continuous, natural values (such as physical dimensions) as being appropriate for double
.
这篇关于什么是 C# 中 SQL Server 数字的等效数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!