Extracting the exponent and mantissa of a Javascript Number

后端 未结 8 648
执笔经年
执笔经年 2020-12-03 03:03

Is there a reasonably fast way to extract the exponent and mantissa from a Number in Javascript?

AFAIK there\'s no way to get at the bits behind a Number in Javascri

8条回答
  •  旧巷少年郎
    2020-12-03 03:56

    If you only need mantissa length,

    Number.prototype.mantissaLength = function(){
        var m = this.toString(), d = m.indexOf('.') + 1;
        return d? m.length - d:0;
    }
    
    var x = 1234.5678;
    var mantL = x.mantissaLength();
    

提交回复
热议问题