不考虑点后的数字



我只想保留点前的数字,后面的数字我不想保留。例如:

double x = 5.6
int y = 5 // the part before dot 
为了这个目的,我有以下代码:
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);     

我试图在resultado上使用分割,但它给了我ArrayOutOfBoundsException的例外。像这样,在最后一行之前:

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

y转换后等于5

double x = 5.6
int y = (int) x;

不只是cast它给你你想要的吗?

double x = 5.6;
int y = (int)x;
System.out.println(y);

相关内容

最新更新