From ada0ec4c77eea1f433e75082a301d87bee35772b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Nov 2013 09:36:38 -0500 Subject: [PATCH] Fix formatting of decimal values when there is no fractionSymbol. When a currency format does not include a fractionSymbol it should be able to format fractional values. Fixes #2253 --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 45 ++++++++++++------- lib/Cake/Utility/CakeNumber.php | 2 +- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index bb3fe92ee7f..9ce874d1d7b 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -141,31 +141,31 @@ public function testFormatDelta() { public function testMultibyteFormat() { $value = '5199100.0006'; $result = $this->Number->format($value, array( - 'thousands' => ' ', - 'decimals' => '&', - 'places' => 3, - 'escape' => false, - 'before' => '', + 'thousands' => ' ', + 'decimals' => '&', + 'places' => 3, + 'escape' => false, + 'before' => '', )); $expected = '5 199 100&001'; $this->assertEquals($expected, $result); $value = 1000.45; $result = $this->Number->format($value, array( - 'thousands' => ',,', - 'decimals' => '.a', - 'escape' => false, + 'thousands' => ',,', + 'decimals' => '.a', + 'escape' => false, )); $expected = '$1,,000.a45'; $this->assertEquals($expected, $result); $value = 519919827593784.00; $this->Number->addFormat('RUR', array( - 'thousands' => 'ø€ƒ‡™', - 'decimals' => '(§.§)', - 'escape' => false, - 'wholeSymbol' => '€', - 'wholePosition' => 'after', + 'thousands' => 'ø€ƒ‡™', + 'decimals' => '(§.§)', + 'escape' => false, + 'wholeSymbol' => '€', + 'wholePosition' => 'after', )); $result = $this->Number->currency($value, 'RUR'); $expected = '519ø€ƒ‡™919ø€ƒ‡™827ø€ƒ‡™593ø€ƒ‡™784(§.§)00€'; @@ -173,9 +173,9 @@ public function testMultibyteFormat() { $value = '13371337.1337'; $result = CakeNumber::format($value, array( - 'thousands' => '- |-| /-\ >< () |2 -', - 'decimals' => '- £€€† -', - 'before' => '' + 'thousands' => '- |-| /-\ >< () |2 -', + 'decimals' => '- £€€† -', + 'before' => '' )); $expected = '13- |-| /-\ >< () |2 -371- |-| /-\ >< () |2 -337- £€€† -13'; $this->assertEquals($expected, $result); @@ -335,6 +335,19 @@ public function testCurrencyWithFractionAndPlaces() { $this->assertEquals($expected, $result); } +/** + * Test that the default fraction handling does not cause issues. + * + * @return void + */ + public function testCurrencyFractionSymbol() { + $result = $this->Number->currency(0.2, '', array( + 'places' => 2, + 'decimal' => '.' + )); + $this->assertEquals('0.2', $result); + } + /** * Test adding currency format options to the number helper * diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 8d43c4169fb..ecba8c04e1c 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -75,7 +75,7 @@ class CakeNumber { * @var array */ protected static $_currencyDefaults = array( - 'wholeSymbol' => '', 'wholePosition' => 'before', 'fractionSymbol' => '', 'fractionPosition' => 'after', + 'wholeSymbol' => '', 'wholePosition' => 'before', 'fractionSymbol' => false, 'fractionPosition' => 'after', 'zero' => '0', 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true, 'fractionExponent' => 2 );