function commerce_currency_round in Commerce Core 7
Rounds a price amount for the specified currency.
Rounding of the minor unit with a currency specific step size. For example, Swiss Francs are rounded using a step size of 0.05. This means a price of 10.93 is converted to 10.95.
Parameters
$amount: The numeric amount value of the price to be rounded.
$currency: The currency array containing the rounding information pertinent to this price. Specifically, this function looks for the 'rounding_step' property for the step size to round to, supporting '0.05' and '0.02'. If the value is 0, this function performs normal rounding to the nearest supported decimal value.
Return value
The rounded numeric amount value for the price.
5 calls to commerce_currency_round()
- CommerceBaseTesterTestCase::testCurrencyRounding in tests/
commerce_base.test - Test the currency value rounding.
- commerce_currency_decimal_to_amount in ./
commerce.module - Converts a price amount to an integer value for storage in the database.
- commerce_currency_format in ./
commerce.module - Formats a price for a particular currency.
- commerce_line_item_handler_area_line_item_summary::render in modules/
line_item/ includes/ views/ handlers/ commerce_line_item_handler_area_line_item_summary.inc - Render the area.
- commerce_payment_handler_field_amount::render in modules/
payment/ includes/ views/ handlers/ commerce_payment_handler_field_amount.inc - Render the field.
File
- ./
commerce.module, line 689 - Defines features and functions common to the Commerce modules.
Code
function commerce_currency_round($amount, $currency) {
if (!$currency['rounding_step']) {
return round($amount, $currency['decimals']);
}
$modifier = 1 / $currency['rounding_step'];
return round($amount * $modifier) / $modifier;
}