w0051977
w0051977

Reputation: 15787

Decimals and Strings

I have a database table with a decimal(25) datatype. The data from this column is loaded into a variable in VB.NET. There are no calculations done on the variable in .NET. Shall I use a decimal data type or a String datatype in .NET?

The same database field is used in a VB6 application. No calculations are done on the field in VB6. What is the best datatype to use in VB6?

The only time the variable is used in either program is as follows:

If variable <> 0 Then
    'Do some logic
End If

Upvotes: 0

Views: 114

Answers (3)

Scott Whitlock
Scott Whitlock

Reputation: 13839

Definitely use the Decimal datatype in .NET.

VB6 has a Decimal datatype but you can't use it directly. However, you can do it like this:

Dim MyDecimal As Variant
MyDecimal = CDec(rs(rowIndex).Value)

That is, the CDec function will convert to the internal decimal type, which you can store in a Variant variable. Unfortunately you lose strong typing, but I think it's better than using a floating point representation.

Upvotes: 0

Deanna
Deanna

Reputation: 24253

Simply put, if it's a decimal number, use a decimal data type, if it's string data, use a string data type, if it's a flag, use a boolean, etc.

Also note that using decimal value as an ID is a bad Idea as computers can't always represent them accurately (Google for floating point inaccuracy).

Upvotes: 2

Ryan Amies
Ryan Amies

Reputation: 4922

Generally, being strongly typed is better, but from your question it wouldn't seem to matter. Personally, I would make it a decimal because what if a calculation were needed to be done on it in the future? You never know what the next developer will be doing to your code so always try to make it as robust as you can.

Upvotes: 3

Related Questions