471,306 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

DATATYPE PROBLEM(cross)

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 ?



Feb 11 '06 #1
1 1318

"Savas Ates" <in da club> wrote in message
news:OE*************@TK2MSFTNGP14.phx.gbl...
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
Feb 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by WhiteRavenEye | last post: by
reply views Thread by Savas Ates | last post: by
1 post views Thread by Troy Jerkins | last post: by
4 posts views Thread by Thomas F.O'Connell | last post: by
1 post views Thread by Savas Ates | last post: by
1 post views Thread by Savas Ates | last post: by
11 posts views Thread by Jake Langham | last post: by
3 posts views Thread by xdli888 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.