1

I'm a new programmer, and I'm coding a basic decimal calculator. (in Java)

If the user inputs how many decimals they want to round to, say 2, how would I incorporate that into the code, and have the answer round to 2 decimals?

Right now, I have something like this:

System.out.printf("%.3f %n", ans);

But that will always round to 3 decimals, no matter what the user input is. Here's a link to the whole code, if necessary. Is there a basic way to this?

krisub
  • 11
  • 1
  • Good question. Thanks for the nice writeup. I've linked to a couple of questions that have the answer. Welcome to Stack Overflow and welcome to programming, cheers! – John Kugelman Jul 17 '20 at 17:26

0 Answers0