+1 to @David Harkness and here is an example:
final double original = 123456789123456789.0; double d = original; d = d + 1.000; // or d++ System.out.println(d == original); // true System.out.printf("%f%n", original); // 123456789123456784,000000 System.out.printf("%f%n", d); // 123456789123456784,000000
And two references:
- [Why not use Double or Float to represent currency?][1]
- *Effective Java, 2nd Edition, Item 48: Avoid float and double if exact answers are required*
if (x % multiplier == 0) { primeLogger = primeLogger + 1.000; } else { primeLogger = primeLogger + 0.000; }
The else branch seems superfluous, I guess you could remove it:
if (x % multiplier == 0) {
primeLogger = primeLogger + 1.000;
}
-
//first the class is declared public class startListingPrimeNumbers {
Later you'll find that comments like this one are just noise. It says nothing more than the code already does, it's obvious from the code itself that it's a class declaration, so I'd remove it. (Clean Code by Robert C. Martin: Chapter 4: Comments, Noise Comments)
1.
double multiplier; ... for (multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {
The multiplier could be declared in the for
loop.
for (double multiplier = 1.000; multiplier <= (x); multiplier = multiplier + 1.000) {
(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)
- Class names should be nouns, instead of verbs and the first letter should be uppercase:
Class and Interface Type Names
Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.
Source: The Java Language Specification, Java SE 7 Edition, 6.1 Declarations
PrimeGenerator
could be a good name for this class.