mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
ead469fff3
commit
bcb3eb89dc
2 changed files with 13 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Reference in a new issue