GeeCON Prague 2014*
The moose likes Java in General and the fly likes int, BigInt, double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "int, BigInt, double" Watch "int, BigInt, double" New topic
Author

int, BigInt, double

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
When should we use int, bigint and double as data types in Java ??
I want to write a java class for Fraction numbers.
I am not sure whether I should declare my private members (numerators and denominators) as int, bigint or double or float ?


<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If you're writing a Fraction class, then it will really help you to think this question through, because it will be fundamental to how your class works.

First, define your requirements for a "numerator" and a "denominator." Will these be whole numbers only? Or might they be floating point? What range will they require? Then list the basic characteristics for each of the types (int, long, double, BigInteger, BigDecimal...): Whole number or floating point? Range? Object or primitive? How do these correspond with your requirements?

Next, consider how you are going to be manipulating these values -- that is, how your methods will perform operations and what form the results will be in. Depending on your approach and your requirements for "precision," you might take a closer look at the BigDecimal class.
[ October 21, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int, BigInt, double