variant double subtype exceed max value

为君一笑 提交于 2019-12-20 04:25:36

问题


when I'm looking at the "Variant Data Type" documantation, it says that variant with subtype of double can support a positive value of maximum "1.79769313486232E308" (15 digits) and that "An error occurs when Variant variables containing Currency, Decimal, and Double values exceed their respective ranges." However, when I'm running the following code:

y = 999999999999999999999999999
y = CStr(CDBL(y))
MsgBox y

I do not recive an error, instead I am getting a msgbox with the following output: "1e+27" (27 is the number of digits in y).

What is the explantion to this? how is "y" stored in the memory?

I havn't found an answer nither in variant documentation nor in CDbl function documentation.

Thanks.


回答1:


On assignment of a numerical quantity to a variant, the vbscript runtime will pick the best possible variant type to match that quantity.

In your case, the literal is too large for an integral type so it assigns it to the double "subtype".

Converting a double of this magnitude to a string will produce a string in scientific notation.

As for your documentation

"1.79769313486232E308" (15 digits)

is a little misleading. Read it as 15 significant figures which is about the precision level for a floating point double precision type.



来源:https://stackoverflow.com/questions/25420146/variant-double-subtype-exceed-max-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!