添加两个双给出错误的结果 [英] add two double given wrong result

查看:147
本文介绍了添加两个双给出错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面这段加法的结果code,在一些神秘的情况下,是不是因为它应该是:

I'm using the following piece of code and under some mysterious circumstances the result of the addition is not as it's supposed to be:

double _west = 9.482935905456543;
double _off = 0.00000093248155508263153;
double _lon = _west + _off;

// check for the expected result
Debug.Assert(_lon == 9.4829368379380981);
// sometimes i get 9.48293685913086 for _lon (which is wrong)

我用在我的应用程序的一些原生的DLL,我怀疑某些DLL是负责这个失算,但我需要找出哪一个。 任何人都可以给我一个提示如何找出我的问题的根源在哪里?

I'm using some native DLLs within my application and i suspect that some DLL is responsible for this 'miscalculation', but i need to figure out which one. Can anyone give me a hint how to figure out the root of my problem?

推荐答案

双不完全准确,请尝试使用十进制而不是

double is not completely accurate, try using decimal instead

采用双和漂浮在小数的advanteage是性能

The advanteage of using double and float over decimal is performance

这篇关于添加两个双给出错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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