Increment Large Double

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a string representing a very large number that I need to increment by 1.
Ocurs that when I try to Convert.ToDouble("123456789012345678901234567890"),
the string representation of my double gives: 1.2345678901234567E+29. But I
need to full representation, without the exponent.

Does anybody can help me ?
Thanks.
 
Cris said:
I have a string representing a very large number that I need to increment
by 1.
Ocurs that when I try to
Convert.ToDouble("123456789012345678901234567890"),
the string representation of my double gives: 1.2345678901234567E+29. But
I
need to full representation, without the exponent.


A double precision floating point number does not have sufficient precision
to store that number down to the last 1. You can use a System.Decimal for
numbers up to 79,228,162,514,264,337,593,543,950,335. For full-precision
arithmetic on larger numbers, you will need to break them down yourself (and
do the carries), or use an arbitrary-precision arithmetic library.

David
 
Cris said:
I have a string representing a very large number that I need to increment by 1.
Ocurs that when I try to Convert.ToDouble("123456789012345678901234567890"),
the string representation of my double gives: 1.2345678901234567E+29. But I
need to full representation, without the exponent.

Does anybody can help me ?

Well, I have a DoubleConverter class which will show you the exact
number - but it'll show you that your original number is almost
certainly not stored as you expect it anyway.

See http://www.pobox.com/~skeet/csharp/floatingpoint.html for more
information and a link to DoubleConverter.

If you're okay with "just" 29 digits, the decimal type should be good
enough.
 

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