Cuberoot没有给出正确的答案 [英] Cuberoot doesn't give correct answer

查看:85
本文介绍了Cuberoot没有给出正确的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我用了这个:

Hello!

I used this:

double secondnum = Math.Pow(num, 1.0 / 3);
            if (secondnum - (int)secondnum == 0)
            {
                return true;
            }
            else return false;


但是,如果我用此numb:66430125进行检查,则它给出404.99999999999989,而在计算器中给出405.那么我该如何解决这个问题?


But, if I check it with this numb:66430125 then it gives 404.99999999999989, and in calculator it gives 405. So How could I solve this one?

推荐答案

浮点Type s( double float )不正确.您必须进行一些舍入,例如:
Floating point Types (double and float) are not exact. You have to do some rounding, for example:
double secondNum = Math.Round(Math.Pow(num, 1.0 / 3), 9);


哈哈.这是正确的答案,具有预期的准确性.
Ha-ha. This is a correct answer with expected accuracy.


这篇关于Cuberoot没有给出正确的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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