-5
在我的應用程序中,我要求用戶提供他們的小時費率,然後我有一個計時錶,我想弄清楚他們自從時間開始以來賺了多少。要做到這一點,我需要把他們的小時費率變成秒鐘,再乘以天文臺的秒數。爪哇分區與整型括號
timer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener()
{
@Override
public void onChronometerTick(Chronometer chronometer){
long timeElapsed = SystemClock.elapsedRealtime() - timer.getBase();
int hours = (int) (timeElapsed/3600000);
int minutes = (int) (timeElapsed - hours * 3600000)/60000;
int seconds = (int) (timeElapsed - hours * 3600000 - minutes * 60000)/1000;
int hrlyRate = Integer.parseInt(hourlyRate.getText().toString());
secondsRate = (hrlyRate/60)/60;
moneyEarned = secondsRate * seconds;
Log.d("hrlyRate", Integer.toString(hrlyRate));
Log.d("secondsRate", Integer.toString(secondsRate));
}
});
假設用戶輸入40到hourlyRate字段這是我從一個EditText得到的,爲什麼是secondsRate = 0的計算?不應該(40/60)/ 60 = $ 0.01 /秒?