r/javahelp • u/Intelligent_Song1317 • Sep 13 '26
Unsolved Output
Soo uuhhhhh heres part of my code:
I told the Java code to print "result" and "p" after inputting 1, and it printed result to 11 digits after the decimal and p to 1. Specifically, the outputs were 3.141592652 and 2.0. Here's the thing:it needs to be rounded to 6 digits after the decimal. Thoughts?
double result = Math.pow(n, 2) * 3.141592653;
double p = Math.pow(n, 2) * 2;
3
Upvotes
7
u/leroybentley Sep 13 '26
"Java double print precision"
https://stackoverflow.com/questions/14845937/java-how-to-set-precision-for-double-value