473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parse Double Conversion

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
Nov 16 '05 #1
3 2292
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.com

"Herb Stevenson" <ta*******@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
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

Nov 16 '05 #2
Herb Stevenson <ta*******@hotmail.com> wrote:
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

--
Jon Skeet - <sk***@pobox.com>
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.com> 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.com>
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
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...
31
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...
5
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,...
3
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...
7
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
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
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...
5
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...
17
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.