Permalink
Browse files

Before this change 0.00 and '0.00' are treated differently. Floats fr…

…om 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).
  • Loading branch information...
dogmatic69 committed Jan 11, 2013
1 parent ead469f commit bcb3eb89dcb4555910555e4b2f26bba53698399d
Showing with 13 additions and 0 deletions.
  1. +12 −0 lib/Cake/Test/Case/Utility/CakeNumberTest.php
  2. +1 −0 lib/Cake/Utility/CakeNumber.php
@@ -253,6 +253,18 @@ public function testCurrency() {
$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);
}
/**
@@ -314,6 +314,7 @@ public static function currency($value, $currency = null, $options = array()) {
$result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole';
$value = (float)$value;
if (!$value) {
if ($options['zero'] !== 0 ) {
return $options['zero'];

0 comments on commit bcb3eb8

Please sign in to comment.