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).
This commit is contained in:
dogmatic69 2013-01-11 17:00:06 +00:00
parent ead469fff3
commit bcb3eb89dc
2 changed files with 13 additions and 0 deletions

View file

@ -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);
}
/**

View file

@ -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'];