Skip to content

Commit

Permalink
If a round value is set with no decimal value the decimal setting def…
Browse files Browse the repository at this point in the history
…aults to 0
  • Loading branch information
leigeber committed Jul 4, 2013
1 parent 04f509d commit db87e8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.3.1

2013-07-04

- If a round value is set with no decimal value the decimal setting defaults to 0

# 1.3.0

2013-05-08
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ExpressionEngine Math Plugin
ExpressionEngine Math Plugin 1.3.1
====

Use Math to execute PHP supported math formulas in ExpressionEngine.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schema_version": "1.0",
"name" : "math",
"label": "Math",
"version": "1.3.0",
"version": "1.3.1",
"types": ["plugin"],
"paths": {
"system": [
Expand Down
11 changes: 6 additions & 5 deletions system/expressionengine/third_party/math/pi.math.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$plugin_info = array (
'pi_name' => 'Math',
'pi_version' => '1.3.0',
'pi_version' => '1.3.1',
'pi_author' => 'Michael Leigeber',
'pi_author_url' => 'http://www.caddis.co',
'pi_description' => 'Use Math to execute PHP supported math formulas.',
Expand Down Expand Up @@ -79,14 +79,15 @@ public function __construct()
}

// Rounding
if ($decimals !== false)
if ($decimals !== false || $round !== false)
{
$mult = pow(10, $decimals);
$dec = ($decimals !== false) ? $decimals : 0;
$mult = pow(10, $dec);

switch ($round)
{
case 'up':
$result = round($result, $decimals, PHP_ROUND_HALF_UP);
$result = round($result, $dec, PHP_ROUND_HALF_UP);
break;
case 'ceil':
$result = ceil($result * $mult) / $mult;
Expand Down Expand Up @@ -130,7 +131,7 @@ public function __construct()
$this->return_data = $result;
}

function usage()
public static function usage()
{
ob_start();
?>
Expand Down

0 comments on commit db87e8e

Please sign in to comment.