|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DATATYPE PROBLEM(cross)(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 ? "Savas Ates" <in da club> wrote in message Integer datatype will always truncate your decimal fraction values.news:OEhAfpwLGHA.648@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 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 Because the value is being represented and stored as a string (just like > It returns right results. typing into a textbox), not a numeric type, so... > There is a problem with decimal records when i want to evaluate this You're expecting .NET to intelligently convert your datatypes for you, which > values.. > > For example > Dim BizdekiFiyat As String > BizdekiFiyat = BizdekiFiyat * 1.05 > > How can i solve this problem ? 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
Other interesting topics
how to obtain further error information?
Can not connect to SQL 2005 Storing Time Only T-SQL Puzzle, well to me at least... problem with DBLib access to SQL Server 2005 General SQL Error Saving HTML into SQL2000 Find specific text in a string Deleting primary key when no foreign records exist? Old dates |
|||||||||||||||||||||||