Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Rounding in Ex. 6.2

+11 votes
My current output is 66.6666...7. What is the code again to a) round my decimal up and then float it to where there are only 2 spots showing? I.e. I need to have it show 66.67


Please and thank you!
asked Feb 5, 2016 in (Winter 15-16) by Eric DeMattia (100 points)

1 Answer

+4 votes

That would be:

System.out.printf("Number: %.2f", num);

Or, there's also this:

String result = String.format("Number: %.2f", num);

which returns a String for your later use, instead of just printing it to the console...

answered Feb 7, 2016 by Forrest Stonedahl (100 points)