diff --git a/includes/Currency.inc b/includes/Currency.inc
index 83ef5b3..6256cbd 100644
--- a/includes/Currency.inc
+++ b/includes/Currency.inc
@@ -60,4 +60,70 @@ 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 replace by the amount, or deleted if there are more
+   *     hashes than the amount has digits.
+   *   - ¤ 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.
+   *   - If the leftmost hash or zero has been reached, but there are still
+   *     amount characters left, it will be suffixed by all remaining amount
+   *     digits.
+   * Example: formatting the euro amount 123456 using '¤-#.##0,00' for results in €1.234,56.
+   *
+   * @return string
+   */
+  function format($amount, $format) {
+    $output = $format;
+
+    $format_groups = array();
+    // Split the format into its characters in a unicode-safe way.
+    $characters = preg_split('//u', $format);
+    // 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'));
+    $amount_characters = array_reverse(str_split(preg_replace('/\D/', '', $amount)));
+    $output = array();
+    foreach (array_reverse($characters, TRUE) as $position => $character) {
+      // Replace replaceable characters, but only if we still have characters
+      // left to replace them with.
+      if ($amount_characters && ($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) {
+          var_dump($first_replaceable_character_position);
+          $output = array_merge($output, $amount_characters);
+        }
+        else {
+          $output[] = array_shift($amount_characters);
+        }
+      }
+      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;
+  }
 }
