Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a BigNumber to a normal number in Typescript

Guys I am fetching the data from smart contract and it gives a big number in response, I want to convert it into a normal number so that I can use it in order to create a bar chart. How can this be done? enter image description here

This is the piece of code I wrote so that I could store the values in an array:

//Creating candidatevoterarray for graph
    for (var i =0; i<= 4; i++){
        const temparray = this.candidatearray[i]
        const count = temparray.voteCount
        // this.candidatevotearray.push(count)
        console.log(count)
  }
like image 258
Vivek Avatar asked Feb 04 '26 20:02

Vivek


1 Answers

as docs https://docs.ethers.io/v5/api/utils/bignumber/ say there is a method .toNumber() in BigNumber

like image 75
Andrei Avatar answered Feb 06 '26 09:02

Andrei