How to use the bignumber.js.BigNumber function in bignumber

To help you get started, we’ve selected a few bignumber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decentraland / eth-connect / src / utils / utils.ts View on Github external
export function getValueOfUnit(_unit: string): BigNumberType {
  let unit = _unit ? _unit.toLowerCase() : 'ether'
  let unitValue = unitMap[unit]
  if (unitValue === undefined) {
    throw new Error(
      "This unit doesn't exists, please use the one of the following units" + JSON.stringify(unitMap, null, 2)
    )
  }
  return new BigNumber(unitValue, 10)
}
github decentraland / eth-connect / src / utils / utils.ts View on Github external
export function toBigNumber(_num: number | string | BigNumberType): BigNumberType {
  let num: any = _num || 0

  if (isBigNumber(num)) {
    return num as BigNumber
  }

  if (typeof num === 'string' && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) {
    return new BigNumber(num.replace('0x', ''), 16)
  }

  return new BigNumber(num.toString(10), 10)
}
github raiden-network / raiden / raiden / ui / web / src / app / components / token-input / token-input.component.ts View on Github external
private getTokenAmount(tokens: string): string {
        const tokenNumber = new BigNumber(tokens);

        if (this.decimalPartIsZero(tokenNumber)) {
            return tokenNumber.toString();
        }

        if (tokenNumber.decimalPlaces() > 4) {
            return tokenNumber.toFixed(this._decimals);
        } else {
            return tokens;
        }
    }
github skycoin / skycoin-web / src / app / components / layout / header / header.component.ts View on Github external
private resetState() {
    this.coins = new BigNumber('0');
    this.price = null;
    this.balance = null;
    this.balanceObtained = false;
    this.isBlockchainLoading = false;
    this.percentage = null;
    this.current = null;
    this.highest = null;
  }
github LedgerHQ / ledger-live-common / src / mock / account.js View on Github external
function ensureNoNegative(operations) {
  let total = BigNumber(0);
  for (let i = operations.length - 1; i >= 0; i--) {
    const op = operations[i];
    const amount = getOperationAmountNumber(op);
    if (total.plus(amount).isNegative()) {
      if (op.type === "IN") {
        op.type = "OUT";
      } else if (op.type === "OUT") {
        op.type = "IN";
      }
    }
    total = total.plus(getOperationAmountNumber(op));
  }
  return total;
}
github liquality / chainabstractionlayer / src / providers / bitcoin / BitcoinLedgerProvider.js View on Github external
getAmountBuffer (amount) {
    let hexAmount = BigNumber(amount).toString(16)
    hexAmount = padHexStart(hexAmount, 16)
    const valueBuffer = Buffer.from(hexAmount, 'hex')
    return valueBuffer.reverse()
  }
github LedgerHQ / ledger-live-desktop / src / components / RequestAmount / index.js View on Github external
handleChangeAmount = (changedField: string) => (val: BigNumber) => {
    const { getReverseCounterValue, max, onChange } = this.props
    if (changedField === 'left') {
      onChange(val.gt(max) ? max : val)
    } else if (changedField === 'right') {
      const leftVal = getReverseCounterValue(val) || BigNumber(0)
      onChange(leftVal.gt(max) ? max : leftVal)
    }
  }
github sablierhq / sablier / packages / frontend / src / pages / PayWithSablier / index.jsx View on Github external
getBlockDeltaFromNow(time) {
    const { block } = this.props;
    const now = block.timestamp.unix();
    const delta = Math.abs(time.subtract(now, "second").unix());
    const deltaInBlocks = BN(delta).dividedBy(MAINNET_BLOCK_TIME_AVERAGE);
    return BN(block.number.plus(deltaInBlocks).toFixed(0));
  }

bignumber

A pure javascript implementation of BigIntegers and RSA crypto.

Unknown
Latest version published 14 years ago

Package Health Score

39 / 100
Full package analysis

Popular bignumber functions