您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页Android 进度条算法

Android 进度条算法

来源:华佗小知识

// TODO total总长度,current下载长度

double i = current / (double) total * 100;

int progress = (int) Math.ceil(i);

pdu.setTvProgress(progress + "/100%");

1.Math.round():根据“round”的字面意思“附近、周围”,可以猜测该函数是求一个附近的整数,看下面几个例子就明白。

小数点后第一位<5

正数:Math.round(11.46)=11

负数:Math.round(-11.46)=-11

小数点后第一位>5

正数:Math.round(11.68)=12

负数:Math.round(-11.68)=-12

小数点后第一位=5

正数:Math.round(11.5)=12

负数:Math.round(-11.5)=-11

总结:(小数点后第一位)大于五全部加,等于五正数加,小于五全不加。

2.Math.ceil():根据“ceil”的字面意思“天花板”去理解;

例如:

Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=12

Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-11

3.Math.floor():根据“floor”的字面意思“地板”去理解;

例如:

Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=11

Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-12

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务