Skip to content

Commit

Permalink
Fix formatting with locales using , as decimal separator
Browse files Browse the repository at this point in the history
Fixes #2958
  • Loading branch information
markstory committed Jun 19, 2012
1 parent f9ddc9c commit 001e89b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Utility/CakeNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ public function testToReadableSize() {
$this->assertEquals($expected, $result);
}

/**
* test toReadableSize() with locales
*
* @return void
*/
public function testReadableSizeLocalized() {
$restore = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'nl_NL');
$result = $this->Number->toReadableSize(1321205);
$this->assertEquals('1,26 MB', $result);

$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 512);
$this->assertEquals('512,00 GB', $result);
setlocale(LC_NUMERIC, $restore);
}

/**
* testToPercentage method
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/CakeNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ class CakeNumber {
/**
* Formats a number with a level of precision.
*
* @param float $number A floating point number.
* @param float $number A floating point number.
* @param integer $precision The precision of the returned number.
* @return float Formatted float.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision
*/
public static function precision($number, $precision = 3) {
return sprintf("%01.{$precision}f", $number);
return sprintf("%01.{$precision}F", $number);
}

/**
Expand Down

0 comments on commit 001e89b

Please sign in to comment.