-3
public class MyClass {
    public static void main(String args[]) {
      double x=120.38;
      System.out.println(Math.round(x‬));
    }
}

Output: 120

But I want an output of 121 Rounding off any decimal values to 1 whole number

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    Does this answer your question? [Java Round up Any Number](https://stackoverflow.com/questions/4540684/java-round-up-any-number) – Ryan M Feb 07 '20 at 02:37
  • Using Math.ceil() solves it – Tangub City Fire Station Feb 07 '20 at 02:46
  • *"[Rounding off](https://en.wiktionary.org/wiki/round_off)"* To almost everybody, that means rounding to **nearest** number, and `120` is the nearest whole number to `120.38`. Did you perhaps mean you want rounding **up**? Perhaps it would be a good idea to check the javadoc of [`RoundingMode`](https://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html) to learn the Java terminology used for naming the various rounding modes: Up, Down, Ceiling, Floor, Half-Up (aka "round off"), Half-Down, and Half-Even (aka "Banker's rounding"). – Andreas Feb 07 '20 at 03:27

2 Answers2

1

Replace Math.round with Math.ceil

Ryan M
  • 18,333
  • 31
  • 67
  • 74
0

Try to use : Math.ceil(x) It will works for you