Decimal 数据类型的精度是多少?

What is the accuracy of the Decimal data type?

我找不到任何地方表明 VBA 有一个数字 e 的特殊变量,所以我认为大量的小数位就足够了。 手册说明如下:

You can use Decimal variables for money values. The advantage is the precision of the values. The Double data type is faster and requires less memory, but it is subject to rounding errors. The Decimal data type retains complete accuracy to 28 decimal places.

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/numeric-data-types

我试过Dim e@(“@”是手册中的十进制标识符),以及这种格式

Dim MyDecimal As Variant
MyDecimal = CDec(3000000000000) 

来自 https://bettersolutions.com/vba/data-types/decimal-data-type.htm

但是,当我尝试使用值 2.7182818284590452353602874713 初始化 e 时,它会向下舍入为 2.71828182845905。这里发生了什么?小数点后28位真的不能用吗?

What's going on here? Can 28 decimal places not actually be utilized?

这是因为,当您这样做时,该值被读取为 Double,因此在 CDec 转换之前被截断为该数据类型可以容纳的值它。

? CDec(2.7182818284590452353602874713)
 2.71828182845904 

? CDec(CDbl("2.7182818284590452353602874713"))
 2.71828182845904 

? CDec("2.7182818284590452353602874713")
 2.7182818284590452353602874713