You are here

function commerce_currency_amount_to_decimal in Commerce Core 7

Converts a price amount to a decimal value based on the currency.

Parameters

$amount: The price amount to convert to a decimal value.

$currency_code: The currency code of the price whose decimals value will be used to divide by the proper divisor when converting the amount.

Return value

The decimal amount depending on the number of places the currency uses.

12 calls to commerce_currency_amount_to_decimal()
CommerceCartTestCaseAnonymousToAuthenticated::testCommerceCartAnonymousToAuthenticated in modules/cart/tests/commerce_cart.test
Test anonymous cart conversion.
CommerceOrderUIAdminTest::testCommerceOrderUIUpdateLineItems in modules/order/tests/commerce_order_ui.test
Test updating line items within an order.
CommercePaymentUITest::testCommercePaymentAdministration in modules/payment/tests/commerce_payment_ui.test
Test the adding payments using administration pages.
CommerceProductUIAdminTest::testCommerceProductUIAddProduct in modules/product/tests/commerce_product_ui.test
Test the add product process.
CommerceProductUIAdminTest::testCommerceProductUIEditProduct in modules/product/tests/commerce_product_ui.test
Test the edit process for a product.

... See full list

File

./commerce.module, line 790
Defines features and functions common to the Commerce modules.

Code

function commerce_currency_amount_to_decimal($amount, $currency_code) {
  static $divisors;

  // If the divisor for this currency hasn't been calculated yet...
  if (empty($divisors[$currency_code])) {

    // Load the currency and calculate its divisor as a power of 10.
    $currency = commerce_currency_load($currency_code);
    $divisors[$currency_code] = pow(10, $currency['decimals']);
  }
  return $amount / $divisors[$currency_code];
}