PC Review


Reply
Thread Tools Rate Thread

When adding a decimal of value 0.000 it loses its bits

 
 
kalleg@-NOSPAM-hotmail.com
Guest
Posts: n/a
 
      13th Jul 2004
Hi,

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 NumberOfDecimals(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.

I can't understand why the value changes when I am adding it. I really need to the information about how many decimal the value contains.

Any suggestions/explanations ??

/Carl

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a Decimal to SqlServer loses the fraction =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= Microsoft ADO .NET 11 20th Apr 2007 08:34 AM
Importing Excel Spreadhseet loses data's decimal places tamula@aol.com Microsoft Access 2 11th Sep 2006 01:17 AM
decimal to 16 bits binary conversion in Excel? xcgames Microsoft Excel Worksheet Functions 2 27th Mar 2006 12:19 AM
Access Imports from Excel as text, loses decimal when converting b =?Utf-8?B?QmlsbA==?= Microsoft Access External Data 2 13th Sep 2005 10:50 PM
Access to Excel currency field loses decimal formatting =?Utf-8?B?TWFyZ2FyZXQ=?= Microsoft Access External Data 4 17th May 2004 02:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 AM.