Parse Double Conversion

  • Thread starter Thread starter Herb Stevenson
  • Start date Start date
H

Herb Stevenson

Hello. I have a very large string reprentation of a number, for example
"1000001002003004005006007008009010". If I user Double.Parse, I get
something like 1.0000010020030041E+33 as my output. I need to do a mod 900
conversion on this long string value (i.e. loop thru the number consistently
dividing by 900). The exponential notation seems to be causing some
precision problems as I divide.

Is there a way to have the double represnted as the entire number?

Thank you
Herb
 
Herb,

Unfortunately, you are using a number that can not be represented by
Decimal, and a number that is also large enough to loose precision when
stored in a double. Because of this, you will have to resort to something
else. Java had something like Number, or BigNumber, but .NET doesn't have
an equivalant. You will have to create a routine/class that can handle
this, as well as a representation for your number.

Hope this helps.
 
Herb Stevenson said:
Hello. I have a very large string reprentation of a number, for example
"1000001002003004005006007008009010". If I user Double.Parse, I get
something like 1.0000010020030041E+33 as my output. I need to do a mod 900
conversion on this long string value (i.e. loop thru the number consistently
dividing by 900). The exponential notation seems to be causing some
precision problems as I divide.

Is there a way to have the double represnted as the entire number?

You won't get precise integer values with doubles that size. You should
use the decimal type instead, so long as that's got the appropriate
range.

See http://www.pobox.com/~skeet/csharp/floatingpoint.html
and http://www.pobox.com/~skeet/csharp/decimal.html
 
Nicholas Paldino said:
Unfortunately, you are using a number that can not be represented by
Decimal, and a number that is also large enough to loose precision when
stored in a double. Because of this, you will have to resort to something
else. Java had something like Number, or BigNumber, but .NET doesn't have
an equivalant. You will have to create a routine/class that can handle
this, as well as a representation for your number.

Oops - I hadn't noticed that even the sample number is outside
decimal's range.

There's an implementation of BigInteger at
http://www.codeproject.com/csharp/BigInteger.asp

I haven't used it myself though.
 

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

Back
Top