-3

I am trying to round up 5.1 to the next whole number. I tried using math round, but it only rounds it to 6 if the value is 5.5 or over.

    int value = 51;
    double dataPerPage = 10;

    double amountOfPages = (double) value / dataPerPage;
    System.out.println(value + "/" + dataPerPage + " = " + amountOfPages);

    int sum = (int) Math.round(amountOfPages);
    System.out.println("Total: " + sum);
user2357112
  • 260,549
  • 28
  • 431
  • 505
Java Gamer
  • 567
  • 3
  • 9
  • 24

1 Answers1

1

Use Math.ceil() in this case

int sum = (int) Math.ceil(amountOfPages);
System.out.println("Total: " + sum);
Justin Sp
  • 17
  • 2