You are here

function payment_amount_human_readable in Payment 7

Convert an amount as a float to a human-readable format.

Parameters

float $amount:

string $currency_code:

Return value

string

6 calls to payment_amount_human_readable()
PaymentMethodController::validate in ./payment.classes.inc
Validate a payment against a payment method and this controller. Don't call directly. Use PaymentMethod::validate() instead.
paymentreference_form_process_paymentreference in modules/paymentreference/paymentreference.module
Implements form process callback for paymentreference elements.
PaymentTestPaymentAmountFormElementWebTestCase::testValidation in tests/payment_test/tests/PaymentTestPaymentAmountFormElementWebTestCase.test
Test validation.
payment_form_process_amount in ./payment.ui.inc
Implements form process callback for a payment_amount element.
payment_form_process_amount_validate in ./payment.ui.inc
Implements form validate callback for a payment_amount element.

... See full list

File

./payment.module, line 886
Hook implementations and shared functions.

Code

function payment_amount_human_readable($amount, $currency_code = NULL) {
  if (payment_currency_version() === 2) {
    $currency = currency_load($currency_code);
    if ($currency) {
      return $currency
        ->format($amount);
    }
  }
  $amount_string = number_format($amount, 2, '.', '');
  $decimal_separator_position = strpos($amount_string, '.');
  $arguments = array(
    '!currency_code' => $currency_code,
    '!units' => substr($amount_string, 0, $decimal_separator_position),
    '!cents' => substr($amount_string, $decimal_separator_position + 1),
  );
  return $currency_code ? t('!currency_code !units.!cents', $arguments) : t('!units.!cents', $arguments);
}