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 2 3559
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
> 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 -...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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: 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...
| |