你怎么能写双变量的具体陈述 [英] how can u write the specific statement for double varibles

查看:92
本文介绍了你怎么能写双变量的具体陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我有两个双变量,比如



  double  ds,ds1; 





ds,ds1存储值



关于我提到的要求如



  if (ds.Equals (ds1))
{


}





之后我的要求有点改变,即ds1比等于ds



你怎么能写这个声明。其实我写的等于ds,ds1



请帮帮我。



谢谢你。

解决方案

  if (ds1 > ;  = ds)
{

}





你应该通过一个关于学习.net基础知识的论坛不是学习如何从头开始编码的最佳场所,我们无法回答你所有的小问题。


首先,使用运算符,而不是 System.Object.Equal

  if (ds >  ds1) //    
if (ds > = ds1) //
if (ds == ds1)< span class =code-com > // 如果这是C#: - )



但要小心==。在大多数计算中,您不应使用此运算符。您需要了解浮点类型只能提供数学实数的近似表示。只有在一定程度上才能考虑平等。例如,您可能需要检查两个值是否足够接近:

 如果( System.Abs(ds  -  ds1)<  delta) //    
// 其中delta是绝对精度

在其他情况下,您需要以相对准确度进行操作。



-SA

揭开C#浮点平等与关系的神秘面纱操作 [ ^ ]

Actually i have two double varibles like as

double ds,ds1;



ds,ds1 stores the values

based on the requirement i mentioned like as

if(ds.Equals(ds1))
{


}



after that my requirement little bit change i.e ds1 is grater than equal to ds

how can u write the this statement. Actually i write equal to ds,ds1

please help me.

thank u.

解决方案

if (ds1 >= ds)
{

}



You should go through a book on learning .net basics as a forum isn't the best place to learn how to code from scratch, we can't be answering every little question you have.


First of all, use operators, not System.Object.Equal:

if (ds > ds1) //
if (ds >= ds1) //
if (ds == ds1) // if this is C# :-)


But be very careful with ==. In most calculations, you should not use this operator. You need to understand that the floating-point types can only provide approximate representation of mathematical real numbers. The equality should only be considered with certain accuracy. For example, you may need to check up if two values are "close enough":

if (System.Abs(ds - ds1) < delta) //
// where delta is some absolute accuracy

In other cases, you need to operate with relative accuracy.

—SA


Demystify C# floating-point equality and relation operations[^]


这篇关于你怎么能写双变量的具体陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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