Skip to content

Commit

Permalink
bug #26781 [Form] Fix precision of MoneyToLocalizedStringTransformer'…
Browse files Browse the repository at this point in the history
…s divisions on transform() (syastrebov)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Fix precision of MoneyToLocalizedStringTransformer's divisions on transform()

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        |

Related issue #21026.
Previous PR #24036.
Similar fix for `transform()` method.

Commits
-------

f94b7aa fix rounding from string
  • Loading branch information
fabpot committed May 17, 2018
2 parents e1f553d + f94b7aa commit 05d69bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Expand Up @@ -78,6 +78,16 @@ public function testFloatToIntConversionMismatchOnReversTransform()
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
IntlTestHelper::requireFullIntl($this, false);
\Locale::setDefault('de_AT');

$this->assertSame(3655, (int) $transformer->reverseTransform('36,55'));
}

public function testFloatToIntConversionMismatchOnTransform()
{
$transformer = new MoneyToLocalizedStringTransformer(null, null, MoneyToLocalizedStringTransformer::ROUND_DOWN, 100);
IntlTestHelper::requireFullIntl($this, false);
\Locale::setDefault('de_AT');

$this->assertSame('10,20', $transformer->transform(1020));
}
}
Expand Up @@ -708,6 +708,7 @@ private function round($value, $precision)
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
$roundingCoef = pow(10, $precision);
$value *= $roundingCoef;
$value = (float) (string) $value;

switch ($roundingModeAttribute) {
case self::ROUND_CEILING:
Expand Down
Expand Up @@ -428,6 +428,7 @@ public function formatRoundingModeRoundHalfUpProvider()
// array(1.125, '1.13'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -451,6 +452,7 @@ public function formatRoundingModeRoundHalfDownProvider()
array(1.125, '1.12'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -474,6 +476,7 @@ public function formatRoundingModeRoundHalfEvenProvider()
array(1.125, '1.12'),
array(1.127, '1.13'),
array(1.129, '1.13'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -498,6 +501,7 @@ public function formatRoundingModeRoundCeilingProvider()
array(-1.123, '-1.12'),
array(-1.125, '-1.12'),
array(-1.127, '-1.12'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -522,6 +526,7 @@ public function formatRoundingModeRoundFloorProvider()
array(-1.123, '-1.13'),
array(-1.125, '-1.13'),
array(-1.127, '-1.13'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -546,6 +551,7 @@ public function formatRoundingModeRoundDownProvider()
array(-1.123, '-1.12'),
array(-1.125, '-1.12'),
array(-1.127, '-1.12'),
array(1020 / 100, '10.20'),
);
}

Expand All @@ -570,6 +576,7 @@ public function formatRoundingModeRoundUpProvider()
array(-1.123, '-1.13'),
array(-1.125, '-1.13'),
array(-1.127, '-1.13'),
array(1020 / 100, '10.20'),
);
}

Expand Down

0 comments on commit 05d69bb

Please sign in to comment.