在 VBA 精度问题中比较双精度

编程入门 行业动态 更新时间:2024-10-26 14:36:56
本文介绍了在 VBA 精度问题中比较双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法在 Excel VBA 中比较 2 个双精度值

I have trouble comparing 2 double in Excel VBA

假设我有以下代码

Dim a as double Dim b as double a = 0.15 b = 0.01

对 b 进行几次操作后,b 现在等于 0.6

After a few manipulations on b, b is now equal to 0.6

然而与双数据类型相关的不精确让我头疼,因为

however the imprecision related to the double data type gives me headache because

if a = b then //this will never trigger end if

你知道如何去除双精度类型的尾随不精确吗?

Do you know how I can remove the trailing imprecision on the double type?

推荐答案

您无法比较浮点值是否相等.请参阅有关比较浮点数的文章" 讨论如何处理内在错误.

You can't compare floating point values for equality. See this article on "Comparing floating point numbers" for a discussion of how to handle the intrinsic error.

除非您事先确定浮点数的绝对范围是多少,否则它不像与恒定误差范围进行比较那么简单.

It isn't as simple as comparing to a constant error margin unless you know for sure what the absolute range of the floats is beforehand.

更多推荐

在 VBA 精度问题中比较双精度

本文发布于:2023-10-28 13:45:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精度   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!