字符串方法 str.toUpperCase() 返回一个大写化处理的字符串。
toFixed(n) 将数字舍入到给定的精度
num.toString(base) 返回在给定 base 进制数字系统中 num 的字符串表示形式。
base 的范围可以从 2 到 36。默认情况下是 10。
let num = 255;
alert( num.toString(16) ); // ff
alert( num.toString(2) ); // 11111111
Math.random()
返回一个从 0 到 1 的随机数(不包括 1)。
随机生成0.1.2
math.floor(math.random()*3)向下取整且随机数不可能大于*后面的数字
Math.floor
向下舍入:3.1 变成 3,-1.1 变成 -2。
Math.ceil
向上舍入:3.1 变成 4,-1.1 变成 -1。
Math.round
向最近的整数舍入:3.1 变成 3,3.6 变成 4,中间值 3.5 变成 4。
Math.trunc(IE 浏览器不支持这个方法)
移除小数点后的所有内容而没有舍入:3.1 变成 3,-1.1 变成 -1。
Math.max(a, b, c…) 和 Math.min(a, b, c…)
从任意数量的参数中返回最大值和最小值。
Math.pow(n, power)
返回 n 的给定(power)次幂。
小数:
使用 Math.floor,Math.ceil,Math.trunc,Math.round 或 num.toFixed(precision) 进行舍入。
请确保记住使用小数时会损失精度。