dAppBooster
    Preparing search index...

    Function formatNumber

    • Formats a numeric value according to the specified number type formatting rules.

      This function serves as the main entry point for number formatting throughout the application. It applies consistent formatting based on the context where the number is displayed (e.g., token amounts, fiat prices, portfolio balances) using predefined formatter rules.

      Parameters

      • input: Nullish<number>

        The numeric value to format (can be null or undefined)

      • Optionaltype: NumberType = NumberType.TokenNonTx

        The formatting type to apply

      • Optionalplaceholder: string = '-'

        Value to return if input is null or undefined

      Returns string

      The formatted number as a string

      // Format a token balance
      formatNumber(0.0005, NumberType.TokenNonTx);
      // Returns: '<0.001'
      // Format a fiat price with default parameters
      formatNumber(1234.567, NumberType.FiatTokenPrice);
      // Returns: '$1,234.57'
      // Format a token amount for a transaction with custom placeholder
      formatNumber(null, NumberType.TokenTx, 'N/A');
      // Returns: 'N/A'
      // Format a gas price
      formatNumber(0.0099, NumberType.FiatGasPrice);
      // Returns: '<$0.01'