473,698 Members | 2,445 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 3354


"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
14409
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
6370
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
4102
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
1440
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
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
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
8897
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
7729
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
6521
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2002
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.