In my app I ask the user to provide their hourly rate, I then have a Chronometer which I want to work out how much they have earned since the time started. To do this I need to turn their hourly rate into a seconds rate and multiply it by the seconds from the Chronometer.
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));
}
});
Say the user enters 40 into the hourlyRate field which I get from an EditText, why is the calculation of secondsRate = 0? Shouldn't it be (40 / 60) / 60 = $0.01 / second?