如何转换为小数 [英] how to convert to decimal

查看:82
本文介绍了如何转换为小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我设计了一种表单,用户可以在其中插入他的教育信息,因此其中之一就是AverageMark.在我的数据库中,其数据类型为小数(2,2).
但是当我想插入它时,Asp.net无法将其转换为有效的小数,这将引发异常,我的代码的一部分是这样的:

Hi.
i have designed a form that user insert his educational information in it , so one of them is AverageMark. in my DB it''s datatype is decimal(2,2).
but when i want to insert it , Asp.net can not convert it to a valid decimal an will throw an exception , a part of my code is like this:

cmd.Parameters.Add("@Average", SqlDbType.Decimal).Value = Convert.ToDecimal(Average.Text.Trim());



我将感谢您解决问题.



i will be thank to solve the problem.

推荐答案

我想您的数字不符合decimal(2,2)定义的允许范围(即-.99.99).
I suppose your numbers don''t fit in the allowed range defined by decimal(2,2) (that is -.99 to .99).


这篇关于如何转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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