ChemPare Documentation - v0.0.0
    Preparing search index...

    Function toUSD

    • Converts a given amount from any supported currency to USD. Uses real-time exchange rates from the Hexarate API. Results are rounded to 2 decimal places for standard currency format.

      Parameters

      • amount: number

        The amount to convert

      • fromCurrencyCode: valueof

        The source currency code (e.g., 'EUR', 'GBP')

      Returns Promise<number>

      The converted amount in USD, formatted to 2 decimal places

      // Convert 100 EUR to USD
      await toUSD(100, 'EUR')
      // Returns 118.45 (if rate is 1.1845)

      // Convert 1000 JPY to USD
      await toUSD(1000, 'JPY')
      // Returns 9.12 (if rate is 0.00912)

      // Chain conversions
      const price = parsePrice('€50.00');
      if (price) {
      const usdAmount = await toUSD(price.price, price.currencyCode);
      }