private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
}
};
当前结果= 00.15.546,期望结果00.15.5
毫秒是我希望1位数的3位数
答案 0 :(得分:2)
If(milliseconds %10<50)
milliseconds = milliseconds/100;
else
milliseconds = milliseconds/100 + 1;
从头开始它会给你一个十进制数,因为计时器不是我的坏人。尝试类似的东西: Math.round(毫秒* 100)/ 100; \