0

I am a new programmer, I would like to know how to round to the nearest hundredth. Here is the code

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    System.out.print("Input first number: ");
    double num1 = in.nextDouble();

    System.out.print("Input second number: ");
    double num2 = in.nextDouble();

    System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));

    System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));

    System.out.println(num1 + " x " + num2 + " = " + (num1 * num2));

    System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
  }
}

please answer with the code to round to the nearest hundredth. Thank You.

cackles
  • 1
  • 2
  • If it is just for output, use a format with `printf`. Otherwise, multiply by 100, round to the nearest integer and divide by 100. – Henry Sep 22 '20 at 03:21
  • java round off questions have been answered before try the given solutions if you have any problems let us know: https://stackoverflow.com/questions/11701399/round-up-to-2-decimal-places-in-java – Ali Tahir Sep 22 '20 at 03:23

0 Answers0