Home All Groups Group Topic Archive Search About

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

Author
30 Jun 2006 4:53 AM
Jordan
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

Author
30 Jun 2006 5:16 AM
Göran Andersson
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...

Jordan wrote:
Show quote
> 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
Author
30 Jun 2006 8:14 AM
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.
--
Show quote
"Jordan" <Jor***@discussions.microsoft.com> wrote in message
news:BAEA37AA-F1CD-40D3-AFCC-9BFBA2276011@microsoft.com...
> 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
Author
2 Jul 2006 1:49 PM
Jon Skeet [C# MVP]
Nick Malik [Microsoft] <nickmalik@hotmail.nospam.com> wrote:
> Use the Decimal Datatype, not double.

That much I agree with.

> Double is a floating point number.  Decimal is a fixed radix number and will
> have no problem with your 18 digit long value.

Well, Decimal is a floating point type as well. Both double and decimal
have a fixed radix - for double it's 2, and for decimal it's 10.

See
http://www.pobox.com/~skeet/csharp/floatingpoint.html
http://www.pobox.com/~skeet/csharp/decimal.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

AddThis Social Bookmark Button