How to convert 0x Protocol BigNumber to String in Javascript

Viewed 2861

I'm getting the market order and limit order's amount and price as a 0x Protocol BigNumber format. And I'm willing to save it as a numeric value to SQL database, so I need to convert BigNumber to String.

I used this command:

BigNumber.toString()

But I got 200000000000000000 while current BigNumber's value is 0.2.

How can I convert BigNumber to the correct numeric string?

2 Answers

Databases are smart enough to do it on their own, so if you give them a string number and if you've defined it to be numeric value in the schema they can do it on their own. Database adapters also smart enough to give numeric values in string format while retrieving them from the database.

In short, you should not try to convert anything that is the point of it. You should rely on database, do all your math in the database.

Related