Browse Source

Before this change 0.00 and '0.00' are treated differently. Floats from the database are returned as the string
version while doing calculations will normally end up as floats.

This causes output differences on pages like order totals or invoices where there is a mix of calculated values
and database values.

Number::currency(0.00, 'GBP') -> £0.00
Number::currency('0.00', 'GBP') -> 0p

Both versions will return `£0.00` (or whatever 0 is configured to return).

dogmatic69 13 years ago
parent
commit
bcb3eb89dc
2 changed files with 13 additions and 0 deletions
  1. 12 0
      lib/Cake/Test/Case/Utility/CakeNumberTest.php
  2. 1 0
      lib/Cake/Utility/CakeNumber.php

+ 12 - 0
lib/Cake/Test/Case/Utility/CakeNumberTest.php

@@ -253,6 +253,18 @@ class CakeNumberTest extends CakeTestCase {
 		$result = $this->Number->currency(0.5, null, array('fractionSymbol' => false, 'fractionPosition' => 'before', 'wholeSymbol' => '$'));
 		$expected = '$0.50';
 		$this->assertEquals($expected, $result);
+
+		$result = $this->Number->currency(0, 'GBP');
+		$expected = '£0.00';
+		$this->assertEquals($expected, $result);
+
+		$result = $this->Number->currency(0.00000, 'GBP');
+		$expected = '£0.00';
+		$this->assertEquals($expected, $result);
+
+		$result = $this->Number->currency('0.00000', 'GBP');
+		$expected = '£0.00';
+		$this->assertEquals($expected, $result);
 	}
 
 /**

+ 1 - 0
lib/Cake/Utility/CakeNumber.php

@@ -314,6 +314,7 @@ class CakeNumber {
 		$result = $options['before'] = $options['after'] = null;
 
 		$symbolKey = 'whole';
+		$value = (float)$value;
 		if (!$value) {
 			if ($options['zero'] !== 0 ) {
 				return $options['zero'];