I wish to round up a number in android application with coding as shown below.
float num1= Float.parseFloat(n1.getText().toString());
float num2= Float.parseFloat(n2.getText().toString());
float outc = num1/input;
int final1;
The application getting user input for num1
and num2
, and perform to find outc. I wish to rounding up the outc
to become an integer final1
where like below:
if outc = 3.8 , final1= 4
if outc = 8.01 , final1= 9
if outc = 12.21 , final1= 13
if outc = 20.45 , final1= 21
*only involve positive value
I try to search for solution, and found that mostly they are normal rounding up solution like this. It that anyway to perform round up as I mentioned? Thank you.
Math.ceil()
int result = (int) Math.ceil(outc);
BTW, you can't name variable final
, it is reserved word.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With