-3

In Java, how can I round a decimal to the next highest int?
So that 3.1 would become 4, 4.6 becomes 5, 4.5 becomes 5, 1.004 becomes 2, etc...
This probably a silly question but I can't figure it out...

Sorry for this being a duplicate. I spent about an hour on google and 15 min on here trying be find it but I only got the normal rounding (1.5 -> 2, 1.2 -> 1) so I figured I may as well ask.

tzq33tdq
  • 1
  • 5

2 Answers2

1

Use Math.ceil. This will round up to nearest integer.

Brett Okken
  • 6,210
  • 1
  • 19
  • 25
1
    int roundedNum = (int) Math.ceil(decimalNum);
     /* where decimalNum should be a double */
4aRk Kn1gh7
  • 4,259
  • 1
  • 30
  • 41