VBA单VS双数据类型

VBA单VS双数据类型

本文介绍了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

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

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

为您评论re 此处.

您可以在此处进行访问.

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

08-22 19:53