浮法铸造问题 [英] Float casting issue

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

问题描述

嗨古鲁兹

我有一个问题,我有两个浮点型变量,其精度数字为11位,如下图所示.

I have an issue , i have two variables of float type having precision figure of 11 digits as shown in following figure.

firstvalue = 10.0000000001

firstvalue = 10.0000000001

第二个值= 10.0000000002

second value = 10.0000000002

       firstval = float.Parse(txtfirstvalue.Text);
                secondval = float.Parse(txtsecvalue.Text);
  if(firstval == secondval)
                {
                   字符串res ="a == b 第一个条件为真";
                    richTextBox1.Text + = res + Environment.NewLine;
                }

      firstval = float.Parse(txtfirstvalue.Text);
                secondval = float.Parse(txtsecvalue.Text);
 if (firstval == secondval)
                {
                    string res = " a == b  First Condition is true";
                    richTextBox1.Text += res + Environment.NewLine;
                }

此返回值相等,这是错误的,图1小于图2.强制转换有什么问题,我应该输入一些数字格式等吗.

this return men equal which is wrong , figure 1 is less then figure 2. what is wrong in casting , should i put some number format etc..

致谢


Ali Muhammad

Ali Muhammad

推荐答案

使用double代替float.

Use double instead of float.

double firstval = double.Parse(firstvalue);

double secondval = double.Parse(secondvalue);

double secondval = double.Parse(secondvalue);


顺便说一句,float变量不能带11个小数点.因此最好使用double而不是float

By the way, float variable can't carry 11 decimal points. So better to use double instead float


这篇关于浮法铸造问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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