Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal data type in Visual Basic 6.0

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.

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

like image 429
Navaneeth K N Avatar asked Jul 22 '09 02:07

Navaneeth K N


People also ask

What data type is decimal in VB?

Precision. Decimal is not a floating-point data type. The Decimal structure holds a binary integer value, together with a sign bit and an integer scaling factor that specifies what portion of the value is a decimal fraction.

What is the data type for a decimal?

The decimal data type is a machine-independent method that represents numbers of up to 32 significant digits, with valid values in the range 10 -129 - 10 +125. When you define a column with the DECIMAL( p ) data type, it has a total of p (< = 32) significant digits.

Which data type is used to store decimal values VBA?

The Single data type stores precision numbers—numbers with decimal places or fractional numbers. The data type is similar to Double, but the range is smaller. Use this data type to store values from –3402823E38 to –1.401298E–45 or from 1.401298E–45 to 3.402823E38.

How do you declare decimals?

{ DECIMAL | DEC } [(precision [, scale ])] The precision must be between 1 and 31. The scale must be less than or equal to the precision. If the scale is not specified, the default scale is 0. If the precision is not specified, the default precision is 5.


1 Answers

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.

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

Dim myDec As Variant
myDec = CDec(1.234)

See if that works.

like image 99
Scott Whitlock Avatar answered Sep 20 '22 09:09

Scott Whitlock