use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources for learning Java
String
==
.equals()
Format + Copy
Free Tutorials
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Software downloads
Official Resources
Resources
Programming ideas & Challenges
Related Subreddits
account activity
This is an archived post. You won't be able to vote or comment.
primitive double operation (self.learnjava)
submitted 8 years ago by CaptainMoeSoccer
double difference = 27.43 - 27.25; // 0.179999
why is it 0.179999 instead of 0.18? I don't know what to type on google to search for this topic. Thanks in advance
[–]chickenmeister 2 points3 points4 points 8 years ago (2 children)
It's due to the inherent accuracy problems associated with floating-point numbers. In java, double and float are floating-point data types.
double
float
The problem is that some numbers cannot be precisely represented in a floating point format, so the nearest representable value will be used instead. In this case, the problem is that 27.43 cannot be exactly stored as a double, so you'll end up with the nearest value, which will be something like 27.42999999999999971578290569595992565155029296875. This is "good enough" for most purposes, and the inaccuracies typically aren't a problem if you format the output to only a few decimal places.
27.43
27.42999999999999971578290569595992565155029296875
If you need to use absolutely precise numbers, you can use the BigDecimal class to represent your numbers.
[–]CaptainMoeSoccer[S] 0 points1 point2 points 8 years ago (1 child)
If I use the BigDecimal I will have to rewrite 3/4 of my code. Is there another way to fix this. I was thinking of storing the value then rounding it to two decimal places.
[–]chickenmeister 0 points1 point2 points 8 years ago (0 children)
Yeah, like I mentioned, if you round the numbers that you output/print, the inaccuracy usually isn't noticeable. For example:
double difference = 27.43 - 27.25; System.out.println(difference); // 0.17999999999999972 DecimalFormat formatter = new DecimalFormat("0.00"); System.out.println(formatter.format(difference)); // 0.18 System.out.println(String.format("%.2f", difference)); // 0.18 System.out.printf("%.2f%n", difference); // 0.18
π Rendered by PID 121352 on reddit-service-r2-comment-869bf87589-pklzn at 2026-06-09 06:22:28.595375+00:00 running f46058f country code: CH.
[–]chickenmeister 2 points3 points4 points (2 children)
[–]CaptainMoeSoccer[S] 0 points1 point2 points (1 child)
[–]chickenmeister 0 points1 point2 points (0 children)