什么是 C# 中 SQL Server 数字的等效数据类型 [英] What is the equivalent datatype of SQL Server's Numeric in C#

查看:37
本文介绍了什么是 C# 中 SQL Server 数字的等效数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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.

decimaldouble 是 .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.)

您应该根据要表示的值在 decimaldouble 之间进行选择 - 我通常认为人造"、人工值(尤其是金钱)) 适用于 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 数字的等效数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆