2

I am converting a long Sting of numbers values to number data type with Number() and parseInt() method of js but it is returning a hexadecimal value. Does anybody know how to convert a long string values of number to Number data type?

// "1245458787546574878756756754561464567867"(type:String) to 1245458787546574878756756754561464567867 (type:Number)

var str = "1245458787546574878756756754561464567867";
console.log(Number(str)); //1.2454587875465749e+39
console.log(parseInt(str)); //1.2454587875465749e+39
console.log(parseInt(str,10)); //1.2454587875465749e+39
console.log(str.length); //40
Nishant
  • 20,354
  • 18
  • 69
  • 101
RohanArihant
  • 2,560
  • 4
  • 19
  • 29
  • 3
    It's not hexadecimal value but decimal expressed in exponential form. It is a number. – marekful Jan 28 '19 at 12:17
  • 2
    what is actually the problem? the numer is too long to be converted to 64 bit float. the first with `Number` shound work, as with an unary plus. the other ones change the numbera to integera and should work with a given integer number as well. – Nina Scholz Jan 28 '19 at 12:17
  • @NinaScholz I simply want to convert the data type String to Number and values will remain same don't want it to be converted to 64 bit float – RohanArihant Jan 28 '19 at 15:38
  • the number type in javascript is 64 bit float. – Nina Scholz Jan 28 '19 at 15:40
  • If you are requesting a reopen on the question, can you explain why your question is not answered in the referenced questions? – Argyll Jul 18 '19 at 17:41

0 Answers0