Rounding with Math.round

What is the syntax for using Math.round?

i.e.: is this right (if rounding to 2 decimal places)?

double decimal = Math.round((100*(4/3))/100.0);

and would this work?:

int places = 2;

int roundInt = (int)Math.pow(10, n);

double roundDouble = Math.pow(10, n);

double fraction = Math.round((roundInt * (4 / 3)) / roundDouble);

[385 byte] By [sonyvaioa] at [2007-10-1 2:21:13]
# 1
oops: replace line:int places = 2;with:int n = 2;
sonyvaioa at 2007-7-8 11:29:35 > top of Java-index,Java Essentials,Java Programming...
# 2

This is kind of a dilemma. Earlier today you wrote this in another thread:

"As much as your "advice" helps, the java docs provide only methods for the BigDecimal/Integer objects. They don't show complete syntax, and don't contain examples. Fortunately, I have avoided the "35-years-old-and-still-living-in-my-mother's-basement-and-aren't-even-professi onal-programmers" path and have enough of a life that I try not to spend all day reading about Java syntax."

Now, the answer to your question can be found in the javadocs. But if I tell you the answer, that will imply that I am a "35-years-old-and-still-living-in-my-mother's-basement-and-aren't-even-professi onal-programmers" and there's no way I would admit to that in public. So sorry, can't help you.

Torgila at 2007-7-8 11:29:35 > top of Java-index,Java Essentials,Java Programming...
# 3
Why don't you try it? Does it give what you expect?Why/Why not?What happens when you trySystem.out.println(4/3);vs System.out.println(4.0/3.0);why would this be different?
evnafetsa at 2007-7-8 11:29:35 > top of Java-index,Java Essentials,Java Programming...
# 4
try thisdouble result = Math.round(value * Math.pow(10, (double) decimals)) / Math.pow(10, (double) decimals);where the variable value stores the value you want to round offand decimals store the no of decimal points
sonu512a at 2007-7-8 11:29:35 > top of Java-index,Java Essentials,Java Programming...