每天都有新发现 2009年10月21日 Decimal 和存储过程OUTPUT

本文详细介绍了C#中decimal类型的特性及其应用场景,特别是在财务和货币计算中的优势。通过对比浮点类型,阐述了decimal类型在精度上的优势,并提供了一个使用decimal类型作为存储过程输出参数的C#示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

decimal(C# 参考)

decimal 关键字表示 128 位数据类型。同浮点型相比,decimal 类型具有更高的精度和更小的范围,这使它适合于财务和货币计算。decimal 类型的大致范围和精度如下表所示。

大致范围:±1.0 × 10-28 到 ±7.9 × 1028

精度:28 到 29 位有效位

.NET Framework 类型:System.Decimal

如果希望实数被视为 decimal 类型,请使用后缀 m 或 M

 

存储过程中返回值 OutPut的使用举例!

在c#代码中的调用。

        public string GetInpourTrackCumulativeResult()
        {
            using (SqlConnection connection = GetSqlConnection())
            {
                SqlCommand command = new SqlCommand("InpourTrack_GetCumulativeResult", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@ReturnCumulativeResult",SqlDbType.Decimal).Direction =ParameterDirection.Output;
                
                connection.Open();
                command.ExecuteNonQuery();


                string CumulativeResult = command.Parameters["@ReturnCumulativeResult"].Value.ToString();
                connection.Close();
                return CumulativeResult;
            }
        }

数据库中存储过程:

CREATE PROCEDURE [dbo].[InpourTrack_GetCumulativeResult]
	@ReturnCumulativeResult Decimal OUTPUT
AS
BEGIN
	
	SET NOCOUNT ON;

    set @ReturnCumulativeResult=( SELECT SUM(AccountNO) FROM InpourTrack)

END
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值