Convert to Long from Double that is over 18 digit long from Oracle

G

Guest

This is a serious bug in .NET 1.1

Using SQL select one field from Oracle table,
This column Oracle data type is: Number(18),
the field value is: 235312035283022003
which is the correct value.

However, using DataReader,
(We want the end result is long type, the only way is GetDouble(reader,0))

Here is the horrible result .NET Returns:

long viewId = 0;//We want the end result is long type,
double dViewId = reader.GetDouble(0);
viewId = (long)dViewId; // we get 235312035283022016
string sViewId = dViewId.ToString("R");//we get "2.35312035283022E+17"
sViewId = dViewId.ToString("F0");//we get 235312035283022000
viewId = long.Parse(sViewId);//235312035283022000

No matter what, we cannot get the correct value:
235312035283022003

This bug happenend when double value reaching 18 digit long.
It is fine when under 17 digit.

Any known work around?
How Microsoft proved .NET is able to be mission-critical?

We are a leading Telecom company, currently reaching the buggy-threshold in
our billing system due to this bug. Any help are appreciated.

Thanks.
Jordan
 
G

Guest

Why are you sending the value as a double? That means that the
information is lost before it even reaches the .NET code.

Not even .NET can recreate information out of thin air...
 
N

Nick Malik [Microsoft]

Use the Decimal Datatype, not double.

Double is a floating point number. Decimal is a fixed radix number and will
have no problem with your 18 digit long value. The limit for decimal is 28
significant digits.

http://msdn2.microsoft.com/en-us/library/364x0z75.aspx

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
J

Jon Skeet [C# MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top