473,405 Members | 2,279 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,405 software developers and data experts.

Variable type to hold largest whole number

Which variable type (c#) can whole the largest whole number? I know this
sounds silly but as double and decimal are made for numbers with decimals I
am not sure.

Also if anybody knows of any library for .NET that would allow me to deal
with **VERY** large whole numbers.

Thanks in advance

JT.
Oct 13 '06 #1
5 11015
Hello, John!

JWhich variable type (c#) can whole the largest whole number? I know
Jthis
Jsounds silly but as double and decimal are made for numbers with
Jdecimals I
Jam not sure.

JAlso if anybody knows of any library for .NET that would allow me to
Jdeal
Jwith **VERY** large whole numbers.

maybe you unsingned long will satisfy your needs?

ulong type has the foollowing range
0 to 18,446,744,073,709,551,615

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Oct 13 '06 #2
John <Jo**@discussions.microsoft.comwrote:
Which variable type (c#) can whole the largest whole number? I know this
sounds silly but as double and decimal are made for numbers with decimals I
am not sure.

Also if anybody knows of any library for .NET that would allow me to deal
with **VERY** large whole numbers.
Well, what are your restrictions? For instance, the range of double is
much greater than the range of decimal, and it will store a bigger
whole number - but it won't store *every* whole number within that
range accurately.

Decimal, however, can never become "inaccurate" at 0DP - in other
words, it will always accurately represent whole numbers, and it can
store any whole number within its range.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 13 '06 #3
By whole number I mean: A number that doesn't contain a fraction, so not too
sure what you mean by "can never become 'inaccurate' " basically I am trying
to write a program that finds primary numbers I have been told that once I
reach the limit of what a variable type can hold and lets say add 1, it
doesn’t through an error it just provides me with an incorrect "random"
number. Thus why I want to find out what is the best variable type to for
this project (find primary numbers) and also know what the limitations are
within the .net framework for very long numbers and whether there are any
special classes (free or commercial to hold very large numbers
hundred/thousands of digits).

"Jon Skeet [C# MVP]" wrote:
John <Jo**@discussions.microsoft.comwrote:
Which variable type (c#) can whole the largest whole number? I know this
sounds silly but as double and decimal are made for numbers with decimals I
am not sure.

Also if anybody knows of any library for .NET that would allow me to deal
with **VERY** large whole numbers.

Well, what are your restrictions? For instance, the range of double is
much greater than the range of decimal, and it will store a bigger
whole number - but it won't store *every* whole number within that
range accurately.

Decimal, however, can never become "inaccurate" at 0DP - in other
words, it will always accurately represent whole numbers, and it can
store any whole number within its range.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #4
John <Jo**@discussions.microsoft.comwrote:
By whole number I mean: A number that doesn't contain a fraction, so not too
sure what you mean by "can never become 'inaccurate' " basically I am trying
to write a program that finds primary numbers I have been told that once I
reach the limit of what a variable type can hold and lets say add 1, it
doesn?t through an error it just provides me with an incorrect "random"
number.
Well, it won't provide you with a random number, but a whole number
stored in a double + 1 may well not give you a whole number - and the
next exactly representable integer may well be significantly more.
Thus why I want to find out what is the best variable type to for
this project (find primary numbers) and also know what the limitations are
within the .net framework for very long numbers and whether there are any
special classes (free or commercial to hold very large numbers
hundred/thousands of digits).
If you want to go above 28 digits, you'll need to use a 3rd party class
- otherwise Decimal should be okay for you.

http://www.codeproject.com/csharp/biginteger.asp may be of interest to
you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #5
Very useful thank a lot Jon!

"Jon Skeet [C# MVP]" wrote:
John <Jo**@discussions.microsoft.comwrote:
By whole number I mean: A number that doesn't contain a fraction, so not too
sure what you mean by "can never become 'inaccurate' " basically I am trying
to write a program that finds primary numbers I have been told that once I
reach the limit of what a variable type can hold and lets say add 1, it
doesn?t through an error it just provides me with an incorrect "random"
number.

Well, it won't provide you with a random number, but a whole number
stored in a double + 1 may well not give you a whole number - and the
next exactly representable integer may well be significantly more.
Thus why I want to find out what is the best variable type to for
this project (find primary numbers) and also know what the limitations are
within the .net framework for very long numbers and whether there are any
special classes (free or commercial to hold very large numbers
hundred/thousands of digits).

If you want to go above 28 digits, you'll need to use a 3rd party class
- otherwise Decimal should be okay for you.

http://www.codeproject.com/csharp/biginteger.asp may be of interest to
you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 19 '06 #6

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

Similar topics

5
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in...
4
by: MCollins | last post by:
trying to determine a variable type, specifically that a variable is an integer. i tried using type(var) but that only seemed to produce a response in the command line. is there a built in...
5
by: frankhall36 | last post by:
Yeah, I need some help, I'm not a very good programmer but I've tried a lot of languages, and anyways, I want to start applying programming to physics, and I would like to learn how to make a...
3
by: David Marsh | last post by:
The program calculates the continued fraction representation of the input: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv) { double diff, n, r, i; if(argc != 2)...
6
by: le0 | last post by:
Hi Guys, Can you help me with this? Is there any function that I can use in getting a whole number Example: Input OutPut 12.3 12 1.63 1
4
by: adodotnet20 | last post by:
I'm developing a Windows application and I'm having some problems in making variable accessible to the whole application. I use VS.NET 2005 and I create a database connection object in the method ...
4
by: mouseit | last post by:
If I have a variable of some sort, say x, how can I find out what variable type javascript thinks it is? For example, if I've declared x as 5 earlier, how do I know now whether it's a string or a...
1
by: mertoman | last post by:
Hello, In Adobe LiveCycle Designer 8 I have a form field that users should be able to us to enter a whole number followed by a fraction or a decimal number such as: 45 1/8 or 45.125 I...
10
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.