0

I'd like to get for really big decimal values like e.g. 4.951760157141521e+27 to the matching binaryString using pure javaScript.

I'm aware that 4.951760157141521e+27 not really is a normal integer anymore what also leads to the problem that just using toString(2) does not work anymore.

print = function(i) { console.log(i) }


let myDecimalNumber = 42;   
print(+myDecimalNumber.toString(2));

let myDecimalNumberBIG = 4.951760157141521e+27;   
print(+myDecimalNumberBIG.toString(2));

How can I fix this? My idea was to use something like a bigInt library but it seems like currently I could not find any working solution so I would really appreciate a working example :)

0 Answers0