rounding math

i know this will seem trivial, but can someone show me how to use the math function for rounding?

i need to round for a monetary program...

instead of 67.89999999999999

you could either truncate it to

67.89

or round it to 67.90

either way, i need to know how to do this.

ive tried to figure this out using the java math methods site:

http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Math.html

but still no luck.

[474 byte] By [cvockrodta] at [2007-11-26 20:02:00]
# 1
You can round using Math.round(x) but I'm not sure how you'd round to digits past the decimal.
sjmclean7a at 2007-7-9 23:00:54 > top of Java-index,Java Essentials,New To Java...
# 2
wow.i totally forgot how that was used.thanks : )
cvockrodta at 2007-7-9 23:00:54 > top of Java-index,Java Essentials,New To Java...
# 3
also... how do you create spaces in output such as System.out.print
cvockrodta at 2007-7-9 23:00:54 > top of Java-index,Java Essentials,New To Java...
# 4
nvm, i am being an idiot tonight.i know how to do that
cvockrodta at 2007-7-9 23:00:54 > top of Java-index,Java Essentials,New To Java...
# 5

I'm new at this, but this is how I do it...there's probably a bett er way...

To say The area of the circle is x meters.

System.out.print("The area of the circle is " + x);

System.out.println(" meters.");

Make sure you have the spaces inside of your quotation marks.

sjmclean7a at 2007-7-9 23:00:54 > top of Java-index,Java Essentials,New To Java...
# 6
System.out.println("The area of the circle is " + x + " meters.");System.out.printf("The area of the circle is %d meters.", x);
floundera at 2007-7-9 23:00:55 > top of Java-index,Java Essentials,New To Java...
# 7
what does printf do?
cvockrodta at 2007-7-9 23:00:55 > top of Java-index,Java Essentials,New To Java...
# 8
The printf method is in the PrintWriter class. You should look it up in the API if you want to learn about it.
floundera at 2007-7-9 23:00:55 > top of Java-index,Java Essentials,New To Java...