如何检查小数是否为空 [英] how to check whether decimal is null or not

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

问题描述

如何检查输入的小数是否为空?

how to check whether the enterd decimal is null or not?

推荐答案

输入小数"是什么意思?如果您正在谈论文本框,则可以执行以下操作以检查是否为空:

What do you mean by "entered decimal"? If you''re talking about a textbox, you could do this to check for null:

if (string.isNullOrEmpty(textbox.Text))
{
    // entry is null
}


如果要从数据库查询中获取它:


If you''re getting it from a database query:

if (IsDbNull(myDecimalValue))
{
    // entry is null
}


如果您使用的是可为空的小数(decimal?),则可以检查HasValue 属性

If you are using a nullable decimal (decimal?) you can check the HasValue property

decimal? d;
if (!d.HasValue)
{
//d is null 
}


(很遗憾(:-)),您不能以任何我知道的输入方式输入null小数.如果您确实想为可空类型输入null的值,则可以通过添加一些复选框为空"来人为地进行输入.我认为您不需要它.这样,在所有其他情况下,您都无需检查它.有关如何使用可为空的类型,请参见Jeremy的解决方案.一种模式注释:您还可以选中"if (d == null)",分配"d = null;",依此类推.

—SA
Unfortunately (:-)), you cannot enter null decimal in any ways of entering I know. If you really want to enter the value of null for nullable type you can do it artificially by adding some check box "Is null". I don''t think you need it. In this way, in all other cases you never need to check it. See the solution by Jeremy on how to work with nullable types. One mode note: you can also check "if (d == null)", assign "d = null;", and so on.

—SA


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

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