473,725 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Increment Large Double

I have a string representing a very large number that I need to increment by 1.
Ocurs that when I try to Convert.ToDoubl e("123456789012 345678901234567 890"),
the string representation of my double gives: 1.2345678901234 567E+29. But I
need to full representation, without the exponent.

Does anybody can help me ?
Thanks.

Feb 10 '07 #1
2 3357


"Cris" <Cr**@discussio ns.microsoft.co mwrote in message
news:21******** *************** ***********@mic rosoft.com...
>I have a string representing a very large number that I need to increment
by 1.
Ocurs that when I try to
Convert.ToDoubl e("123456789012 345678901234567 890"),
the string representation of my double gives: 1.2345678901234 567E+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

Feb 10 '07 #2
Cris <Cr**@discussio ns.microsoft.co mwrote:
I have a string representing a very large number that I need to increment by 1.
Ocurs that when I try to Convert.ToDoubl e("123456789012 345678901234567 890"),
the string representation of my double gives: 1.2345678901234 567E+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.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

98
14419
by: jrefactors | last post by:
I heard people saying prefix increment is faster than postfix incerement, but I don't know what's the difference. They both are i = i+1. i++ ++i Please advise. thanks!!
13
6376
by: kailasam | last post by:
Hello, Iam having a doubt. Which is more efficient post increment or Pre increment? I have read that preincrement is efficient than Post increment. Iam not able to think how it is? For an independent statement i++ and ++i which is more efficient? Regards Kailasam
45
4114
by: Robbie Hatley | last post by:
Hello, group. I've been doing too much C++ programming lately, and I'm starting to become rusty at some aspects of the C way of doing things, esp. efficient low-level data copies. Specificially, I just wrote the following, but I don't know if this is safe: void Func(char* left, char* right) { chat temp_left = {'\0'};
6
1441
by: Allan Stirrett | last post by:
Hi, I've got a section of code that basically goes like so: int l_Index = 0; std::set<intl_Set; while(l_Index < 10) { l_Set.insert(l_Index++); }
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.