I have these two variables
double num = 540.512 double sum = 1978.8
Then I did this expression
double total = Math.round((num/ sum * 100) * 10) / 10;
but I end up with 27.0.
In fact I have many other variables and when I use them in the expression I always get a 0 in the tenth's place.
Helpful method I created a while ago...
private static double round (double value, int precision) { int scale = (int) Math.pow(10, precision); return (double) Math.round(value * scale) / scale; }
2.1m questions
2.1m answers
60 comments
57.0k users