@pathmaker-digital/pmd-utilities - v2.2.6
    Preparing search index...

    Function convertCurrency

    • Converts an amount from one currency rate to another.

      Parameters

      • amount: number

        The amount to convert.

      • fromRate: number

        The exchange rate of the original currency (e.g., USD).

      • toRate: number

        The exchange rate of the target currency (e.g., EUR).

      Returns number

      The converted amount rounded to 2 decimal places.

      // Convert $10 USD to EUR, where 1 USD = 1 and 1 EUR = 0.85
      const converted = convertCurrency(10, 1, 0.85);
      console.log(converted); // Output: 8.5
      // Convert 100 GBP to JPY, where 1 GBP = 1.2 and 1 JPY = 0.0075
      const yen = convertCurrency(100, 1.2, 0.0075);
      console.log(yen); // Output: 0.63