我有点二进制,例如 0.10010011
如何将其转换为十进制 float ?
(0.10010011 = 0.57421875)
var a = 0.10010011
var b = point_bin2dec(a)
console.log(b) // 0.57421875
最佳答案
function point_bin2dec(num) {
var parts = num.toString().split('.');
return parseInt(parts[0], 2) + (parts[1] || '').split('').reduceRight(function (r, a) {
return (r + parseInt(a, 2)) / 2;
}, 0);
}
document.write(point_bin2dec(0.10010011));
关于javascript - 将点二进制转换为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50221635/