ganache test returns characters instead of numbers

by bbusdriver   Last Updated August 14, 2019 01:28 AM

 mapping(uint256 => uint256) public amount;

 function saveAmount(uint256 _id, uint256 _amount) public {
    amount[_id] = _amount;

I have a function that saves amount in mapping. When I test this using ganache, I get a weird character values. For example,

instance.saveAmount(1, 100000, {from: account[1]})

then, to see the amount,

instance.amount(1) which yields

BN: 186a0

Why is it not showing 100000?

Answers 1

The call is returning the hex value as a big number.

0x186a0 in hex is 100000 in decimal.

It is a big number because it is easier to deal with ETH values in that format.

To get the number representation from the call, you should do the following:

var amount = instance.amount(1)
August 13, 2019 23:30 PM

Related Questions

Updated February 20, 2019 12:28 PM

Updated December 21, 2018 06:28 AM

Updated April 25, 2018 12:28 PM

Updated July 25, 2018 07:28 AM