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 ?
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