Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplified format method
Hello Daniel/James,
please verify carefully my changes and thoughts.

1. No need to set $value = $value

2. Using $value both as the conversion parameter name and formatted value can be a little confusing. I changed to $amount (I could have re-used $number as well)

3. If we are not returning a formatted string we could simply return the rounded value.
  • Loading branch information
maks feltrin committed Nov 24, 2015
1 parent 08a7457 commit 3fb9f9d
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions upload/system/library/cart/currency.php
Expand Up @@ -60,39 +60,27 @@ public function format($number, $currency = '', $value = '', $format = true) {
$currency = $this->code;
}

if ($value) {
$value = $value;
} else {
if (!$value) {
$value = $this->currencies[$currency]['value'];
}

if ($value) {
$value = (float)$number * $value;
} else {
$value = $number;
$amount = $value ? (float)$number * $value : (float)$number;

$amount = round($amount, (int)$decimal_place);

if (!$format) {
return $amount;
}

$string = '';

if (($symbol_left) && ($format)) {
if ($symbol_left) {
$string .= $symbol_left;
}

if ($format) {
$decimal_point = $this->language->get('decimal_point');
} else {
$decimal_point = '.';
}

if ($format) {
$thousand_point = $this->language->get('thousand_point');
} else {
$thousand_point = '';
}

$string .= number_format(round($value, (int)$decimal_place), (int)$decimal_place, $decimal_point, $thousand_point);
$string .= number_format($amount, (int)$decimal_place, $this->language->get('decimal_point'), $this->language->get('thousand_point'));

if (($symbol_right) && ($format)) {
if ($symbol_right) {
$string .= $symbol_right;
}

Expand Down

0 comments on commit 3fb9f9d

Please sign in to comment.