473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: DataRow alters stored System.Decimal values.

I am storing a 0.000 a System.Decimal in a DataRow.
On retrieval the value is only 0 without the three decimal places.

It looks like the Get property returns System.Decimal. Zero, but
why????
I can't figure out why the design is so that the DataRow "alters" the
value entered.

In my application a decimal column in a row of a specific table has a
fix number of decimal places according to certain premises. The
premises are quite tedious to calculate so it would be VERY nice if I
could figure out the number of decimal places by looking at the value
stored. However since 0 (zero) can't be stored with a fix amount of
decimal places, I have to store the number of decimal places for each
column in a secondary information source. This secondary information
source gets really huge. For example: one table out of 255 has about
7000 rows with three decimal columns per row.
Considering the following code

DataRow myRow = myTable.NewRow( );

Decimal myDec = new Decimal( 0, 0, 0, false, 3 ); // 0.000
Console.WriteLi ne(myDecimal + " " + NumberOfDec(myD ec));

myRow["decimal"] = myDec;
Console.WriteLi ne(myRow["decimal"].ToString() + " " +
NumberOfDec((De cimal)myRow["decimal"]));

Where NumberOfDec is

public static int NumberOfDec(Sys tem.Decimal decVal)
{
int[] bits = System.Decimal. GetBits(decVal) ;
int retVal= Convert.ToInt32 (System.BitConv erter.GetBytes( bits[3])[2]);
return retVal;
}

The output of this code is
0 3
0 0

In other words myDec is 0 (zero) but with 3 decimals. But when adding
it to myRow it loses the information about 3 decimals.

When looking at myDec and myRow["decimal"]) in the QuickWatch myDec's
flag property is 196608 but myRow["decimal"]) flag property is 0.

Any suggestions/explanations, is it a bug??

/Carl
Jul 21 '05 #1
2 3602
Gav
why do you have to store the decimal places when they are 0? Just to display
the in the DataRow? Then why don't you just format the output to show 3
decimal places?

Maybe I don't understand your question but it seems like you are storing
data unnecessarily.

"Carl G" <ge*****@hotmai l.com> wrote in message
news:86******** *************** ***@posting.goo gle.com...
I am storing a 0.000 a System.Decimal in a DataRow.
On retrieval the value is only 0 without the three decimal places.

It looks like the Get property returns System.Decimal. Zero, but
why????
I can't figure out why the design is so that the DataRow "alters" the
value entered.

In my application a decimal column in a row of a specific table has a
fix number of decimal places according to certain premises. The
premises are quite tedious to calculate so it would be VERY nice if I
could figure out the number of decimal places by looking at the value
stored. However since 0 (zero) can't be stored with a fix amount of
decimal places, I have to store the number of decimal places for each
column in a secondary information source. This secondary information
source gets really huge. For example: one table out of 255 has about
7000 rows with three decimal columns per row.
Considering the following code

DataRow myRow = myTable.NewRow( );

Decimal myDec = new Decimal( 0, 0, 0, false, 3 ); // 0.000
Console.WriteLi ne(myDecimal + " " + NumberOfDec(myD ec));

myRow["decimal"] = myDec;
Console.WriteLi ne(myRow["decimal"].ToString() + " " +
NumberOfDec((De cimal)myRow["decimal"]));

Where NumberOfDec is

public static int NumberOfDec(Sys tem.Decimal decVal)
{
int[] bits = System.Decimal. GetBits(decVal) ;
int retVal= Convert.ToInt32 (System.BitConv erter.GetBytes( bits[3])[2]);
return retVal;
}

The output of this code is
0 3
0 0

In other words myDec is 0 (zero) but with 3 decimals. But when adding
it to myRow it loses the information about 3 decimals.

When looking at myDec and myRow["decimal"]) in the QuickWatch myDec's
flag property is 196608 but myRow["decimal"]) flag property is 0.

Any suggestions/explanations, is it a bug??

/Carl

Jul 21 '05 #2
> why do you have to store the decimal places when they are 0? Just to display
the in the DataRow? Then why don't you just format the output to show 3
decimal places?
I don't want to store the decimal places. I want to use the fact that
System.Decimal holds the information for me. When the user changes the
field that was 0 (to for instance 0.1234) I want to be able to easily
understand how many decimal places it should have by looking at the
prvious value. It works fine for instance if the value is 1.23 and the
user enters 1.5644, I then now that I should round it to two decimals
1.56

In my application, the number of decimal places can vary for the same
column between different data rows depending on the value of other
columns. Calculating this takes time. So by using the fact that
System.Decimal stores the number of decimal places, I could have speed
things up.
Maybe I don't understand your question but it seems like you are storing
data unnecessarily.


Yes it is unnecessarily. But I do not have a choice since I can't
store 0 in the datarow as 0.000. Storing 3.000 works fine, but not
0.000.
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2170
by: Carl G | last post by:
I have a DataSet with a couple of tables. I have noticed that when I am trying to store a Decimal 0.000 in a datarow, the value is changed to 0, without the information about its decimalplaces. Storing 3.000 works fine but not 0.000. Why is that?
0
324
by: anon | last post by:
I have a datatable of values and I am trying to obtain the values of a range of the columns. Imagine I have a table defined with columns headed "A" through to "Z" Now I decide that I want to count up the amounts between columns E to M Note:All the columns are defined as decimal. I have a main datatable defined at dtMain with all the columns and data in
0
3169
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
2
1900
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have three buttons on a windows form that provide three options for the user the process goes like this user clicks button one and a web service is called that dwnloads a list
1
1331
by: harsha reddy | last post by:
Dear All, I have a front end form which has a couple of dropdown menus which select data from the database based on the value selected, the stored procedure which the program accesses outputs diffrent columns when different values( currently 2) from the drop down are chosen. I also have a Datagrid with bound columns which has all the columns that can be returned, this datagrid has a couple of date columns when i select one value from the...
2
321
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I can't figure out why the design is so that the DataRow "alters" the value entered. In my application a decimal column in a row of a specific table has a fix number of decimal places according to certain premises. The
4
7254
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which - "Modified" of type DateTime - is hidden since it should not be edited by a user. The system handles the update for this column. So, I have hidden (Visible=false) this column on the grid. In order to access the value in this field, I have created a...
2
1006
by: suganya | last post by:
Hi I have to insert two textbox values into the database. In sql server 2005, I have the table named Rs with the following fields Rs decimal(2, 2) date1 datetime In front end I have given the coding as Imports System.Data
0
2135
by: a573851 | last post by:
I have a very lengthy stored procedure that I just inherited. Apparently this stored proc performs poorly. I am reviewing it to see where I can add some efficiencies. I would like to know if there are any tips/tools/doc available that could assist me in UDB stored procedure performance. I see a lot out there on SQL Server, but I can't seem to find any tips for UDB. The procedure is as follows: DROP SPECIFIC PROCEDURE...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.