Excel VBA单VS双数据类型 [英] Excel VBA Single VS Double Data Type

查看:69
本文介绍了Excel VBA单VS双数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为这是一个简单的问题,但是我很难找到答案:

I thought this was a simple question but I'm having such a hard time finding an answer:

我知道Single和Double数据类型存储浮点数.但是我不明白他们可以代表的最大位数?

I understand that the Single and Double data types store floating point numbers. But I don't understand the maximum digits they can represent?

例如,如果我在此简单宏中使用Single数据类型:

For example, if I use the Single data type in this simple macro:

Sub Float()
    Dim Result As Single
    Result = 10 / 3
    MsgBox Result
End Sub

结果为3.333333

The result is 3.333333

有7位数字.但是,当您查看Single可以容纳的范围时-表示它可以容纳更多位数.

There's 7 digits. But when you look at the range that Single can accommodate - it indicates that it can hold way more digits.

与Double类型相同.我将变量更改为Double,则结果为3.33333333333333(15位数字),但是Double可以容纳更多位数吗?

Same thing with the Double type. I change the variable to Double, then the result is 3.33333333333333 (15 digits) but Double can hold way more digits?

我很困惑.

推荐答案

精度最高限制为15个有效数字.其他答案提到单身"为7.

Precision is limited to 15 significant figures max. And other answer mentions 7 for Single.

如果您改为打印到工作表,则会看到以下内容:

If you instead print to the sheet you will see the following:

Public Sub test()
    Dim s As Single
    Dim s2 As Double
    s = 10 / 3
    s2 = 10 / 3
    [A1] = "Single"
    [B1] = s
    [A2] = "Double"
    [B2] = s2
    [B1:B2].NumberFormat = "0.000000000000000000"
End Sub

关于您以后关于精度决定的问题;有一个国际标准对此进行管理.

Regarding your later question as to the decision on precision; there is an international standard governing this.

IEEE 754

浮点算术的IEEE标准(IEEE 754)是1985年制定的浮点计算技术标准由电气和电子工程师协会(IEEE)提供.这该标准解决了在不同浮点中发现的许多问题使得它们难以可靠且便携地使用的实现.现在,许多硬件浮点单元都使用IEEE 754标准.

The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found in the diverse floating point implementations that made them difficult to use reliably and portably. Many hardware floating point units now use the IEEE 754 standard.

有人可能会对此进行纠正,但我相信这是当前的标准.

Someone may correct me on this but I believe this to be the prevailing standard.

为您评论re 此处.

您可以在此处进行访问.

这篇关于Excel VBA单VS双数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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