Visual Basic 6.0中的十进制数据类型

时间:2021-11-06 01:33:26

I need to do calculations (division or multiplication) with very large numbers. Currently I am using Double and getting the value round off problems. I can do the same calculations accurately on C# using Decimal type. I am looking for a method to do accurate calculations in VB6.0 and I couldn't find a Decimal type in VB6.0.

我需要用非常大的数字进行计算(除法或乘法)。目前我正在使用Double并获得价值。我可以使用Decimal类型在C#上准确地进行相同的计算。我正在寻找一种在VB6.0中进行精确计算的方法,我在VB6.0中找不到Decimal类型。

What is the data type used for doing arithmetic calculations with large values and without getting floating point round off problems?

用于进行具有较大值的算术计算而不会出现浮点舍入问题的数据类型是什么?

1 个解决方案

#1


Depending on your data type, you can always use Currency, which is like Decimal(19,4), or 15 digits to the left of the decimal point, and 4 to the right.

根据您的数据类型,您始终可以使用货币,如十进制(19,4),或小数点左侧的15位数,以及右侧的4位数。

In VB6, try using the variant datatype, and casting your numbers to that using CDec, as in:

在VB6中,尝试使用variant数据类型,并使用CDec将数字转换为数字,如下所示:

Dim myDec As Variant
myDec = CDec(1.234)

See if that works.

看看是否有效。

#1


Depending on your data type, you can always use Currency, which is like Decimal(19,4), or 15 digits to the left of the decimal point, and 4 to the right.

根据您的数据类型,您始终可以使用货币,如十进制(19,4),或小数点左侧的15位数,以及右侧的4位数。

In VB6, try using the variant datatype, and casting your numbers to that using CDec, as in:

在VB6中,尝试使用variant数据类型,并使用CDec将数字转换为数字,如下所示:

Dim myDec As Variant
myDec = CDec(1.234)

See if that works.

看看是否有效。