DATATYPE PROBLEM(cross)

S

Savas Ates

I have a column in my table BizdekiFiyat . The datatype = float length =8
(to save money values).. It is impossible to change these attributes for
some reasons.

It has records like This

BizdekiFiyat
110
24
29.5
31.35


I use Vb.Net . I use ExecuteReader To select values from my db..

After first attemp

Dim BizdekiFiyat As Integer OR Dim BizdekiFiyat As Decimal
IT returns
110
24
295
3135

Dim BizdekiFiyat As String
It returns right results.

110
24
29.5
31.35

There is a problem with decimal records when i want to evaluate this
values..

For example
Dim BizdekiFiyat As String
BizdekiFiyat = BizdekiFiyat * 1.05

It is supposed to be
29.5 * 1.05 =30.975
31.35*1.05=32.9175
but it returns
309,75
3291,75

How can i solve this problem ?
 
A

Alec MacLean

Savas Ates said:
I have a column in my table BizdekiFiyat . The datatype = float length =8
(to save money values).. It is impossible to change these attributes for
some reasons.


Dim BizdekiFiyat As Integer OR Dim BizdekiFiyat As Decimal
IT returns
110
24
295
3135

Integer datatype will always truncate your decimal fraction values.

I've had data dimension problems trying to use the Decimal datatype for
holding (SQL) decimal data returned through parameters using MS's EntLib
DAAB. I resolved this by using .NET's Double datatype (though I'd prefer to
know why .NET's decimal gave me the problem in the first place).
Dim BizdekiFiyat As String
It returns right results.

Because the value is being represented and stored as a string (just like
typing into a textbox), not a numeric type, so...
There is a problem with decimal records when i want to evaluate this
values..

For example
Dim BizdekiFiyat As String
BizdekiFiyat = BizdekiFiyat * 1.05

How can i solve this problem ?

You're expecting .NET to intelligently convert your datatypes for you, which
it is valiantly trying to do. You should consider setting Option Strict on
(Tools | Options | Projects | VB Defaults) to prevent loose data typing and
late binding. You should strongly type your datatypes as a matter of god
practice. When you need to convert datatypes, dothis explicitely using
CType(sourceObj, targetType), or the shorthand versions such as Cint(value),
CDbl(value), etc.

As for your calculations: e.g. using Double to store your values, create a
function which you'll call when necessary to do your calculations:

private function MultiplyBizdekiFiyat(Byval origValue as double, Byval
MultiplyBy as double) As Double
'Perform the calculation
MultiplyBizdekiFiyat = origValue * MultiplyBy

'Return the value to the calling method.
return MultiplyBizdekiFiyat

end function

Hope that helps

Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top