Java Round up Any Number
I don't know why you are dividing by 100 but here my assumption int a;
int b = (int) Math.ceil( ((double)a) / 100);
or
int b = (int) Math.ceil( a / 100.0);
Math.ceil()
is the correct function to call. I'm guessing a
is an int
, which would make a / 100
perform integer arithmetic. Try Math.ceil(a / 100.0)
instead.
int a = 142;
System.out.println(a / 100);
System.out.println(Math.ceil(a / 100));
System.out.println(a / 100.0);
System.out.println(Math.ceil(a / 100.0));
System.out.println((int) Math.ceil(a / 100.0));
Outputs:
1
1.0
1.42
2.0
2
See http://ideone.com/yhT0l