Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

round up number in Android

Tags:

android

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.

like image 220
GentleG Avatar asked Sep 07 '25 12:09

GentleG


1 Answers

Math.ceil()

int result = (int) Math.ceil(outc);

BTW, you can't name variable final, it is reserved word.

like image 132
Sergey Glotov Avatar answered Sep 10 '25 00:09

Sergey Glotov