473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.WriteLine(myDecimal + " " + NumberOfDec(myDec));

myRow["decimal"] = myDec;
Console.WriteLine(myRow["decimal"].ToString() + " " +
NumberOfDec((Decimal)myRow["decimal"]));

Where NumberOfDec is

public static int NumberOfDec(System.Decimal decVal)
{
int[] bits = System.Decimal.GetBits(decVal);
int retVal= Convert.ToInt32(System.BitConverter.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 3558
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*****@hotmail.com> wrote in message
news:86**************************@posting.google.c om...
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.WriteLine(myDecimal + " " + NumberOfDec(myDec));

myRow["decimal"] = myDec;
Console.WriteLine(myRow["decimal"].ToString() + " " +
NumberOfDec((Decimal)myRow["decimal"]));

Where NumberOfDec is

public static int NumberOfDec(System.Decimal decVal)
{
int[] bits = System.Decimal.GetBits(decVal);
int retVal= Convert.ToInt32(System.BitConverter.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
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. ...
0
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...
0
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...
2
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...
1
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...
2
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...
4
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 -...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.