dAppBooster
    Preparing search index...

    Function formatNumberOrString

    • Formats a number or string value according to the specified number type.

      This utility function handles both numeric and string inputs by converting string values to numbers before applying the appropriate formatting rules. It provides a convenient way to format values that might come from different data sources in different types.

      Parameters

      • price: Nullish<string | number>

        The numeric value or string representation to format

      • type: NumberType

        The formatting type to apply (e.g., TokenNonTx, FiatTokenPrice)

      Returns string

      The formatted value as a string, or '-' if the input is null or undefined

      // Format a number
      formatNumberOrString(1234.56, NumberType.FiatTokenPrice);
      // Returns: '$1,234.56'
      // Format a string representing a number
      formatNumberOrString('0.0099', NumberType.FiatGasPrice);
      // Returns: '<$0.01'
      // Handle null input
      formatNumberOrString(null, NumberType.TokenNonTx);
      // Returns: '-'