Skip to content
Permalink
Browse files

Fix formatting with locales using , as decimal separator

Fixes #2958
  • Loading branch information...
markstory committed Jun 19, 2012
1 parent f9ddc9c commit 001e89bf3fc57305adf1302adc2664b3c99065aa
Showing with 18 additions and 2 deletions.
  1. +16 −0 lib/Cake/Test/Case/Utility/CakeNumberTest.php
  2. +2 −2 lib/Cake/Utility/CakeNumber.php
@@ -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
*
@@ -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);
}
/**

0 comments on commit 001e89b

Please sign in to comment.
You can’t perform that action at this time.