Ethers.js: FixedNumber with zero decimal causes error

Created on 14 Apr 2021  路  2Comments  路  Source: ethers-io/ethers.js

Problems

Following code causes error.

FixedNumber.fromValue(BigNumber.from('0'), 0).toFormat('fixed128x0');
FixedNumber.fromValue(BigNumber.from('0'), 0, 'fixed128x0');

the error is

Error: invalid BigNumber string (argument="value", value="0.0", code=INVALID_ARGUMENT, version=bignumber/5.1.0)

following is OK

FixedNumber.fromString('0', 'fixed128x0')
=> FixedNumber {
  format: FixedFormat {
    signed: true,
    width: 128,
    decimals: 0,
    name: 'fixed128x0',
    _multiplier: '1'
  },
  _hex: '0x00',
  _value: '0.0',
  _isFixedNumber: true
}

but there is some doubt that _value is "0.0". this may be the cause of the error.

Version

the error can be reproduced on @ethersproject/bignumber:5.1.0.
and I use node v14.16.1.

bug fixed minor-bump

Most helpful comment

This has been fixed in 5.2.0.

Try it out and let me know if there are still any issues. Thanks! :)

All 2 comments

This has been fixed in 5.2.0.

Try it out and let me know if there are still any issues. Thanks! :)

# node 
Welcome to Node.js v14.16.1.
Type ".help" for more information.
> const { BigNumber, FixedNumber } = require('@ethersproject/bignumber')
undefined
> FixedNumber.fromValue(BigNumber.from('0'), 0).toFormat('fixed128x0');
FixedNumber {
  format: FixedFormat {
    signed: true,
    width: 128,
    decimals: 0,
    name: 'fixed128x0',
    _multiplier: '1'
  },
  _hex: '0x00',
  _value: '0',
  _isFixedNumber: true
}

馃憤
@ricmoo thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamdossa picture adamdossa  路  3Comments

crazyrabbitLTC picture crazyrabbitLTC  路  3Comments

PhABC picture PhABC  路  3Comments

jochenonline picture jochenonline  路  3Comments

ricmoo picture ricmoo  路  3Comments