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; }
1.4m articles
1.4m replys
5 comments
56.9k users