0

Im using a nodejs code to download a csv file which also contains 19 digits number. But after downloading Im getting a number in the format like "1.23457E+18". So If I try to expand or format this cells to text or number Im getting last 4 digits as 0000. But My actual number is 1234574654345678987.

        "Unique": jsonResult[i].dcp,

Im assigning like this. If try to add some special characters like

   "UniqueSysReference": jsonResult[i].dcp + "A",

Then Im getting the original number with A. But I need only the actual number. Im using

"json2csvParser". Can anybody please tell me how to fix this issue?

sasi
  • 836
  • 4
  • 17
  • 33

1 Answers1

0

Javascript cannot handle big numbers and their operations. largest exact integral value is 253-1, or 9007199254740991. In ES6, this is defined as Number.MAX_SAFE_INTEGER.

you can use bignumber.js library https://www.npmjs.com/package/bignumber.js .it handles all operations related to big numbers.

//require it
const BigNumber = require('bignumber.js');

 //then you can convert your number to bignumber
    Unique": BigNumber(jsonResult[i].dcp)

  //if you want to show that big number as string
  console.log(BigNumber(jsonResult[i].dcp).toFixed())
Yogesh.Kathayat
  • 974
  • 7
  • 21