0

I have the following variables initialized to the user inputs,

int completedPasses = reader1.nextInt();

int attemptedPasses = reader2.nextInt();

double completionRatio = (250 / 3) * ((completedPasses / attemptedPasses) - 0.3);

How do I round the computation above to a double of one decimal place?

Omeiza
  • 1
  • 1
  • 2

1 Answers1

1

Use DecimalFormat:

     DecimalFormat df = new DecimalFormat("#.#");
     df.format(completionRatio);

Or Math.round:

    Math.round(completionRatio);
elaice
  • 23
  • 3