diff --git a/currency.module b/currency.module
index 39c640c..4046501 100644
--- a/currency.module
+++ b/currency.module
@@ -38,3 +38,9 @@ function currency_views_api() {
     'path' => drupal_get_path('module', 'currency') . '/views',
   );
 }
+
+function currency_init() {
+  ctools_include('export');
+  $currency = ctools_export_crud_load('currency', 'EUR');
+  debug($currency->format(123456789, '¤#,##0.000'));
+}
\ No newline at end of file
diff --git a/includes/Currency.inc b/includes/Currency.inc
index 83ef5b3..182ead2 100644
--- a/includes/Currency.inc
+++ b/includes/Currency.inc
@@ -60,4 +60,67 @@ class Currency extends CurrencyBaseAbstract {
    * @var string
    */
   public $title = '';
+
+  /**
+   * Formats an amount.
+   *
+   * @param integer $amount
+   * @param string $format
+   *   The output equals $format, but the following replacements will be made:
+   *   - Zeroes (0) will be replaced by the amount, or kept if there are more
+   *     zeroes than the amount has digits.
+   *   - Hashes (#) will be replaced by the amount. If there are more hashes
+   *     than the amount has digits, they will be removed, along with any
+   *     contained separators (periods/commas).
+   *   - ¤ will be replaced by the currency sign.
+   *   - XXX will be replaced by the ISO 4217 currency code.
+   *   - 999 will be replaced by the ISO 4217 currency number.
+   *   - Minus signs (-) will be removed if the amount is not negative.
+   *   - If the leftmost hash or zero has been reached and there are still
+   *     digits left, it will be suffixed by all of them.
+   * Example: formatting the euro amount 123456 using '¤-#.##0,00' for results in €1.234,56.
+   *
+   * @return string
+   */
+  function format($amount, $format) {
+    // Split the format into its characters in a unicode-safe way.
+    $characters = array_reverse(preg_split('//u', $format), TRUE);
+    // We keep track of the first replaceable character in the format, so if
+    // the amount has more digits than there are replaceable characters, we
+    // replace the first character by all remaining digits.
+    $first_replaceable_character_position = min(strpos($format, '#'), strpos($format, '0'));
+    $digits = array_reverse(str_split(preg_replace('/\D/', '', $amount)), TRUE);
+    $output = array();
+    foreach ($characters as $position => $character) {
+      // Replace replaceable characters, but only if we still have characters
+      // left to replace them with.
+      if ($digits && ($character == '#' || $character ==='0')) {
+        // If this is the first replaceable character (which we replace last),
+        // replace it by all remaining digits.
+        if ($position == $first_replaceable_character_position) {
+          $output = array_merge($output, $digits);
+        }
+        else {
+          $output[] = array_shift($digits);
+        }
+      }
+      else {
+        $output[] = $character;
+      }
+    }
+    $output = implode(array_reverse($output));
+
+    // Insert the currency sign, code, and number.
+    $output = str_replace('¤', $this->sign, $output);
+    $output = str_replace('XXX', $this->code, $output);
+    $output = str_replace('999', $this->number, $output);
+    // Remove any hashes and redundant separators (periods/commas).
+    $output = preg_replace('/#([#.,]*)#/', '', $output);
+    // Remove the minus sign if the amount is not negative.
+    if ($amount >= 0) {
+      $output = str_replace('-', '', $output);
+    }
+
+    return $output;
+  }
 }
