473,804 Members | 4,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse Double Conversion

Hello. I have a very large string reprentation of a number, for example
"10000010020030 040050060070080 09010". If I user Double.Parse, I get
something like 1.0000010020030 041E+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
Nov 16 '05 #1
3 2305
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Herb Stevenson" <ta*******@hotm ail.com> wrote in message
news:uh******** ******@TK2MSFTN GP11.phx.gbl...
Hello. I have a very large string reprentation of a number, for example
"10000010020030 040050060070080 09010". If I user Double.Parse, I get
something like 1.0000010020030 041E+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

Nov 16 '05 #2
Herb Stevenson <ta*******@hotm ail.com> wrote:
Hello. I have a very large string reprentation of a number, for example
"10000010020030 040050060070080 09010". If I user Double.Parse, I get
something like 1.0000010020030 041E+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

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
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.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

24
3178
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and their types. I would like to somehow store a reference to parsing operations in this array (such as Int32.Parse, Double.Parse, SqlMoney.Parse, etc), so I can invoke the appropriate one without writing a long switch.
31
6655
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
5
5659
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options, NumberFormat Info numfmt) at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info) at System.Double.Parse(String s) ...
3
4634
by: Josh | last post by:
I am writing a program where the user inputs currency in US dollars. I want the program to only accept valid currency input, converting the string into the proper type of variable (double?), and to make sure there are no illegal characters entered so that it doesn't make an error. I basically want it to strip out any characters that aren't numbers, in case the user enters something like "$34.23". So far, in my hours of research today I...
7
2687
by: Joe | last post by:
Hello All: Does anyone know the difference between CType(x,Integer) vs. Integer.Parse(x)? Is there a performance advantage to one or the other? TIA, -- Joe
3
2893
by: Jason S | last post by:
is there any way to use templates to bind integer/floating point constants to a template for compile-time use? e.g. template <double conversion> class meters { const factor = conversion;
2
3502
by: Samuel R. Neff | last post by:
I'm using a quasi open-source project and am running into an exception in double.Parse which is effectively this: double.Parse(double.MinValue.ToString()) System.OverflowException: Value was either too large or too small for a Double. at System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info)
5
64659
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
17
11333
by: Thomas Kowalski | last post by:
Hi, I would like to know whether someone knows a library or function that parses a string containing 3 double numbers in the form like xxxx.yyyyyyyyy xxxx.yyyyyyyyy xxxx.yyyyyyyyy really fast. Currently I am using "sscanf(line.c_str(), "%lf %lf %lf", &x, &y, &z);" which is kind of slow. Thanks in advance, Thomas Kowalski
0
9579
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
10575
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...
0
9144
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
7616
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
6851
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
5520
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
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
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.