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? 7 2136
Hi Carl,
Err, data in dataset is stored in native format and not formatted at all
(3.000 is stored as 3 and 0.000 is stored as 0).
Formating is supposed to happen at UI level (datagrid perhaps).
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Carl G" <ge*****@hotmail.com> wrote in message
news:86**************************@posting.google.c om... 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?
Hi Miha,
Yes, it is not formatted but the decimal value still contains
information about how many decimal it was created with. I want to use
this information in the UI level, but I can't since 0.000 gets
transformed to 0 without the .000. All other decimal values keep the
information about decimal places except for 0.
Look at this example
Decimal dec1 = new Decimal( 0, 0, 0, false, 3 ); //0.000
Decimal dec2 = new Decimal( 3000, 0, 0, false, 3 ); //3.000
myRow["dec1"] = dec1;
myRow["dec2"] = dec2;
When looking at the flags property in quick watch:
dec1 has 196608, ie. 3 decimals
dec2 has 196608, ie. 3 decimals
myRow["dec1"] has 0, ie. 0 decimals !!!!
myRow["dec2"] has 196608, ie. 3 decimals
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:<Oj**************@TK2MSFTNGP12.phx.gbl>... Hi Carl,
Err, data in dataset is stored in native format and not formatted at all (3.000 is stored as 3 and 0.000 is stored as 0). Formating is supposed to happen at UI level (datagrid perhaps).
-- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com
"Carl G" <ge*****@hotmail.com> wrote in message news:86**************************@posting.google.c om... 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?
<"Miha Markic [MVP C#]" <miha at rthand com>> wrote: Err, data in dataset is stored in native format and not formatted at all (3.000 is stored as 3 and 0.000 is stored as 0).
Not as of v1.1 of the framework - decimals remember their precision for
non-zero numbers.
Try this code:
using System;
class Test
{
static void Main()
{
decimal d0 = 1m;
decimal d1 = 1.0m;
decimal d2 = 1.00m;
decimal d3 = 1.000m;
decimal d4 = 1.0000m;
Console.WriteLine (d0);
Console.WriteLine (d1);
Console.WriteLine (d2);
Console.WriteLine (d3);
Console.WriteLine (d4);
}
}
Now the curious thing is that if you change the "1" to a "0", you lose
the information. Here's another program to show what I mean:
using System;
class Test
{
static void Main()
{
ShowDecimal(1m);
ShowDecimal(1.0m);
ShowDecimal(0m);
ShowDecimal(0.0m);
int[] bits = new int[]{0, 0, 0, 65536};
ShowDecimal(new decimal(bits));
}
static void ShowDecimal(decimal d)
{
int[] bits = decimal.GetBits(d);
Console.WriteLine ("{0} {1} {2} {3} {4}",
d, bits[0], bits[1],
bits[2], bits[3]);
}
}
The last entry shows the construction of something which is *logically*
0.0, but still gets displayed as 0. It looks like -0 also gets
displayed as 0 by default.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Jon and Miha
Some information I am not sure of (so no information however to keep in
mind), this is as far as I remember me that I have readed it in the
language.vb group changed in the versions 1.0 and 1.1.
Cor Not as of v1.1 of the framework - decimals remember their precision for non-zero numbers.
Try this code: using System;
class Test { static void Main() { decimal d0 = 1m; decimal d1 = 1.0m; decimal d2 = 1.00m; decimal d3 = 1.000m; decimal d4 = 1.0000m; Console.WriteLine (d0); Console.WriteLine (d1); Console.WriteLine (d2); Console.WriteLine (d3); Console.WriteLine (d4); } }
Now the curious thing is that if you change the "1" to a "0", you lose the information. Here's another program to show what I mean:
using System;
class Test { static void Main() { ShowDecimal(1m); ShowDecimal(1.0m); ShowDecimal(0m); ShowDecimal(0.0m);
int[] bits = new int[]{0, 0, 0, 65536}; ShowDecimal(new decimal(bits)); }
static void ShowDecimal(decimal d) { int[] bits = decimal.GetBits(d); Console.WriteLine ("{0} {1} {2} {3} {4}", d, bits[0], bits[1], bits[2], bits[3]); } }
The last entry shows the construction of something which is *logically* 0.0, but still gets displayed as 0. It looks like -0 also gets displayed as 0 by default.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Cor Ligthert <no**********@planet.nl> wrote: Some information I am not sure of (so no information however to keep in mind), this is as far as I remember me that I have readed it in the language.vb group changed in the versions 1.0 and 1.1.
It definitely changed between 1.0 and 1.1. In 1.0, 1.0 would have been
stored as 1, whereas 1.1, 1.0 would be stored as 1.0. Just to confuse
things ;)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
But why does 0.000 store as 0 instead of 0.000 as it in my opinion should ???
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>... Cor Ligthert <no**********@planet.nl> wrote: Some information I am not sure of (so no information however to keep in mind), this is as far as I remember me that I have readed it in the language.vb group changed in the versions 1.0 and 1.1.
It definitely changed between 1.0 and 1.1. In 1.0, 1.0 would have been stored as 1, whereas 1.1, 1.0 would be stored as 1.0. Just to confuse things ;)
Carl G <ge*****@hotmail.com> wrote: But why does 0.000 store as 0 instead of 0.000 as it in my opinion should ???
I don't know, I'm afraid.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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: john |
last post by:
Hi,All Gurus:
It is kind of complicated, please bear with me and let me know if you have
any questions.
Thanks a lot in advance.
John
I have a csharp method, using emit to dynamically generate...
|
by: VMI |
last post by:
Is it possible to store the data in a datatable in the hard disk instead of
the memory? By default, when a datatable's being filled, the table (and
data) will remain in memory. Would it be possible...
|
by: Newbie |
last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like
the Datagrid is not getting the contents of the Datatable when the button (
btnAddAnotherLaborCategory) is clicked.
...
|
by: Marcel Balcarek |
last post by:
I have serialized an object:
Dim formatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim currentStream As New System.IO.MemoryStream
...
|
by: sdettmers |
last post by:
Hi,
Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net
I have created a login page which attempts to retrieve the users record
from the database and I...
|
by: Brad |
last post by:
I have written some code to manipulate data/records in a MASTER (order
header) and DETAIL (order details) tables.
What I have written is too extensive to post but essentially trying to:
1....
|
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: mercea |
last post by:
Hi guys,
I am taking a column from a table and comparing each row in that table with a similar column in a gridview row by row. For each identical answer, grade increments by 1. after all the rows...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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: 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...
|
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: 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,...
| |