在我的ProgressBar中我想以0.0格式显示进度百分比。我有这个代码,但结果总是向上或向下舍入,而不显示小数点后的数字。Android百分比ProgressBar
double value = Double.valueOf(data);
value = numero_a/numero_b *100;
final float numero_float = (float) value;
new Thread(new Runnable() {
float progressStatus = 0;
Handler handler = new Handler();
public void run() {
while (progressStatus < numero_float) {
progressStatus += 1;
handler.post(new Runnable() {
public void run() {
tvPercentuale.setText(progressStatus+"%");
mProgress.setProgress((int)progressStatus);
问题是,即使如此,值也是四舍五入的。 我想看到47.8%。但现在我看到48.0% – user2996988
然后progressStatus事先被舍入。也许你需要这样做:float progressStatus = 0F; .... progressStatus + = 1F; – runor49
问题是'setProgress'不接受float数据,只接受int。 有没有办法接受float? – user2996988