Skip to content
This repository
Browse code

Fix formatting with locales using , as decimal separator

Fixes #2958
  • Loading branch information...
commit 001e89bf3fc57305adf1302adc2664b3c99065aa 1 parent f9ddc9c
Mark Story authored June 18, 2012
16  lib/Cake/Test/Case/Utility/CakeNumberTest.php
@@ -485,6 +485,22 @@ public function testToReadableSize() {
485 485
 	}
486 486
 
487 487
 /**
  488
+ * test toReadableSize() with locales
  489
+ *
  490
+ * @return void
  491
+ */
  492
+	public function testReadableSizeLocalized() {
  493
+		$restore = setlocale(LC_NUMERIC, 0);
  494
+		setlocale(LC_NUMERIC, 'nl_NL');
  495
+		$result = $this->Number->toReadableSize(1321205);
  496
+		$this->assertEquals('1,26 MB', $result);
  497
+
  498
+		$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 512);
  499
+		$this->assertEquals('512,00 GB', $result);
  500
+		setlocale(LC_NUMERIC, $restore);
  501
+	}
  502
+
  503
+/**
488 504
  * testToPercentage method
489 505
  *
490 506
  * @return void
4  lib/Cake/Utility/CakeNumber.php
@@ -70,13 +70,13 @@ class CakeNumber {
70 70
 /**
71 71
  * Formats a number with a level of precision.
72 72
  *
73  
- * @param float $number	A floating point number.
  73
+ * @param float $number A floating point number.
74 74
  * @param integer $precision The precision of the returned number.
75 75
  * @return float Formatted float.
76 76
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision
77 77
  */
78 78
 	public static function precision($number, $precision = 3) {
79  
-		return sprintf("%01.{$precision}f", $number);
  79
+		return sprintf("%01.{$precision}F", $number);
80 80
 	}
81 81
 
82 82
 /**

0 notes on commit 001e89b

Please sign in to comment.
Something went wrong with that request. Please try again.