You are here

public function AdjustmentTransformer::roundAdjustment in Commerce Core 8.2

Rounds an adjustment to its currency precision.

For example, a USD adjustment will be rounded to 2 decimals.

Parameters

\Drupal\commerce_order\Adjustment $adjustment: The adjustment.

int $mode: The rounding mode. One of the following constants: PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, PHP_ROUND_HALF_ODD.

Return value

\Drupal\commerce_order\Adjustment The rounded adjustment.

Overrides AdjustmentTransformerInterface::roundAdjustment

1 call to AdjustmentTransformer::roundAdjustment()
AdjustmentTransformer::roundAdjustments in modules/order/src/AdjustmentTransformer.php
Rounds adjustments to their currency precision.

File

modules/order/src/AdjustmentTransformer.php, line 111

Class

AdjustmentTransformer

Namespace

Drupal\commerce_order

Code

public function roundAdjustment(Adjustment $adjustment, $mode = PHP_ROUND_HALF_UP) {
  $amount = $this->rounder
    ->round($adjustment
    ->getAmount(), $mode);
  $adjustment = new Adjustment([
    'amount' => $amount,
  ] + $adjustment
    ->toArray());
  return $adjustment;
}