2

Lets say I have a BigInt(66555444333222111) and I want to convert it to float loke the output will be 6.6555444E9.

AdolfJames Urian
  • 97
  • 1
  • 1
  • 9
  • check out https://stackoverflow.com/questions/4293230/how-do-i-convert-an-integer-to-a-float-in-javascript – ash Oct 26 '20 at 04:10
  • Do you want to convert it to a float, or do you want to format it as scientific notation? For example, should `2n**2000n` be Infinity or 1.1481306E602? – Ry- Oct 26 '20 at 04:15
  • https://stackoverflow.com/a/53970656/11954917 – Makwana Prahlad Oct 26 '20 at 04:28
  • Do you know the max int value? I asked a similar question a few days ago and have the math to convert it to float based on the number of bits. I later used the math in the accepted answer to convert a Uint32array to float: https://stackoverflow.com/questions/64470083/how-to-convert-random-integers-into-float-between-0-and-1 – Dshiz Oct 26 '20 at 04:56

1 Answers1

0

You can use the following example:

console.log( Number( BigInt('66555444333222111') ).toExponential() )
Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20