-2

I want to keep only the number before dot, what comes after I don't want to. For example:

double x = 5.6
int y = 5 // the part before dot 

For this purpose I have the following code:

SeekBar tipSeekBar;
EditText tipAmountET;
double tipAmount;
tipAmount = (tipSeekBar.getProgress()) * .01;               
NumberFormat format = NumberFormat.getInstance(Locale.US);
Number number;
number = format.parse(String.valueOf(tipAmount));
double d = number.doubleValue();
String resultado = String.valueOf(d * 100);
tipAmountET.setText(resultado);     

I tried to use the split on resultado, but it gives me the exception ArrayOutOfBoundsException. Like this, before the last line:

String[] split = resultado.split(".");
tipAmountET.setText(split[0]);

2 Answers2

1

y will be equally 5 after this conversion:

double x = 5.6
int y = (int) x;
Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
0

Doesn't just casting it give you what you want?

double x = 5.6;
int y = (int)x;
System.out.println(y);
Jarred Olson
  • 3,075
  • 1
  • 19
  • 34