Rounder.php in Commerce Core 8.2
File
modules/price/src/Rounder.php
View source
<?php
namespace Drupal\commerce_price;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class Rounder implements RounderInterface {
protected $currencyStorage;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->currencyStorage = $entity_type_manager
->getStorage('commerce_currency');
}
public function round(Price $price, $mode = PHP_ROUND_HALF_UP) {
$currency_code = $price
->getCurrencyCode();
$currency = $this->currencyStorage
->load($currency_code);
if (!$currency) {
throw new \InvalidArgumentException(sprintf('Could not load the "%s" currency.', $currency_code));
}
$rounded_number = Calculator::round($price
->getNumber(), $currency
->getFractionDigits(), $mode);
return new Price($rounded_number, $currency_code);
}
}