如何检查双精度值是否为空? [英] How to check if a double is null?

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

问题描述

我正在查询一个数据库,但我得到的一些结果为空.我将这些值设置为数据类型为 double 的变量.让我们称变量为结果".所以我尝试设置一个 if 语句来查看它等于 Null ,这当然不起作用.这是我的 if 语句代码:

I'm querying a database and some of the results I'm getting are null. I'm setting these values to a variable with a datatype of double. Let's call the variable "results". So I tried setting up an if statement to see it equals Null which of course didn't work. Here is the code I have for that if statement:

if (results == null)
{
     results = 0;
}

我用这段代码得到的错误是:

The error I get with this code is:

The operator == is undefined for the argument type(s) double, null

有没有更好的方法来确定它是否为空?

Is there a better way to determine if it's null?

推荐答案

我建议使用 Double 而不是 double 作为您的类型,然后您检查 null.

I would recommend using a Double not a double as your type then you check against null.

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

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