1、语法
number.toString(radix)
2、参数radix说明
可选。规定表示数字的基数,是 2 ~ 36 之间的整数。若省略该参数,则使用基数 10。但是要注意,如果该参数是 10 以外的其他值,则 ECMAScript 标准允许实现返回任意值。
2 - 数字以二进制值显示
8 - 数字以八进制值显示
16 - 数字以十六进制值显示
3、将rgb转hex形式
function rgb2Hex(connectionRatio) {
let r = 80
let g = 143
let b = 211
let rHex = ('0' + parseInt(r).toString(16)).slice(-2)
let gHex = ('0' + parseInt(g).toString(16)).slice(-2)
let bHex = ('0' + parseInt(b).toString(16)).slice(-2)
let sectorColor = '#' + rHex + gHex + bHex
// console.log(sectorColor)
return sectorColor
}
4、参考:https://www.runoob.com/jsref/jsref-tostring-number.html