手机网站模板单页/现在学seo课程多少钱
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
double a = 0.1;double b = 0.50;double c = 0;double d = 0.4;double e = 0.6;double f = 1.3;double g = 1.6;//Math.ceil 表示的是大于某个小数的最小整数的double值; ceiling最高限度 天花板double ceil1 = Math.ceil(a);double ceil2 = Math.ceil(b);double ceil3 = Math.ceil(c);double ceil4 = Math.ceil(d);double ceil5 = Math.ceil(e);//Math.round 表示的是四舍五入,且得到long值long round1 = Math.round(a);long round2 = Math.round(b);long round3 = Math.round(c);long round4 = Math.round(d);long round5 = Math.round(e);//Math.floor 跟Math.ceil相反,表示的是小于某个小数的最大整数值的double类型; floor底板 最底限度double floor1 = Math.floor(a);double floor2 = Math.floor(b);double floor3 = Math.floor(c);double floor4 = Math.floor(d);double floor5 = Math.floor(e);double floor6 = Math.floor(f);double floor7 = Math.floor(g);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30