summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--HISTORY1
-rw-r--r--framework/I18N/core/NumberFormat.php13
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket285.page7
-rw-r--r--tests/FunctionalTests/tickets/tests/Ticket285TestCase.php12
-rw-r--r--tests/unit/I18N/core/NumberFormatTest.php25
6 files changed, 55 insertions, 5 deletions
diff --git a/.gitattributes b/.gitattributes
index 6f6f9da8..e1677ef4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1634,6 +1634,7 @@ tests/FunctionalTests/tickets/protected/pages/Ticket284.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket284.php -text
tests/FunctionalTests/tickets/protected/pages/Ticket284Component.php -text
tests/FunctionalTests/tickets/protected/pages/Ticket284Component.tpl -text
+tests/FunctionalTests/tickets/protected/pages/Ticket285.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket311.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket312.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket54.page -text
@@ -1654,6 +1655,7 @@ tests/FunctionalTests/tickets/tests/Ticket21TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket239TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket27TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket284TestCase.php -text
+tests/FunctionalTests/tickets/tests/Ticket285TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket28TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket54TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket72TestCase.php -text
diff --git a/HISTORY b/HISTORY
index 20d62166..1196cd69 100644
--- a/HISTORY
+++ b/HISTORY
@@ -2,6 +2,7 @@ Version 3.0.3 August 6, 2006
============================
BUG: Ticket#264 - Typos in some exception throw statements (Knut)
BUG: Ticket#268 - THttpResponse.redirect() may fail for some browsers (Qiang)
+BUG: Ticket#285 - NumberFormat Rounding Bug (Wei)
BUG: Ticket#297 - THttpRequest::constructUrl() encoding bug about array GET parameters (Qiang)
BUG: TDataGrid may complain getting ItemType on a non-object if the grid is not data-bound (Qiang)
BUG: TCheckBox.Value should be converted to string (Qiang)
diff --git a/framework/I18N/core/NumberFormat.php b/framework/I18N/core/NumberFormat.php
index 8e715f15..b30e615b 100644
--- a/framework/I18N/core/NumberFormat.php
+++ b/framework/I18N/core/NumberFormat.php
@@ -161,9 +161,14 @@ class NumberFormat
$string = (string)$string;
$dp = strpos($string, '.');
+ $decimalDigits = $this->formatInfo->DecimalDigits;
+// var_dump($decimalDigits);
+ //if not decimal digits, assume 0 decimal points.
+ if(is_int($decimalDigits) && $decimalDigits > 0)
+ $string = (string)round(floatval($string),$decimalDigits);
if(is_int($dp))
- $string = substr($string, 0, $dp);
-
+ $string = substr($string, 0, $dp);
+
$integer = '';
$digitSize = $this->formatInfo->getDigitSize();
@@ -233,7 +238,9 @@ class NumberFormat
$decimalDigits = $this->formatInfo->DecimalDigits;
$decimalSeparator = $this->formatInfo->DecimalSeparator;
-
+
+ //do the correct rounding here
+ //$string = round(floatval($string), $decimalDigits);
if(is_int($dp))
{
if($decimalDigits == -1)
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket285.page b/tests/FunctionalTests/tickets/protected/pages/Ticket285.page
new file mode 100644
index 00000000..9aeb37e9
--- /dev/null
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket285.page
@@ -0,0 +1,7 @@
+<com:TContent ID="Content">
+
+<com:System.I18N.TNumberFormat Value="349.999" Pattern="#.00" />
+
+<com:System.I18N.TNumberFormat Value="349.99" Pattern="#.00" />
+
+</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/tickets/tests/Ticket285TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket285TestCase.php
new file mode 100644
index 00000000..cd681c58
--- /dev/null
+++ b/tests/FunctionalTests/tickets/tests/Ticket285TestCase.php
@@ -0,0 +1,12 @@
+<?php
+
+class Ticket285TestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $this->open('tickets/index.php?page=Ticket285');
+ $this->assertTextPresent('350.00');
+ $this->assertTextPresent('349.99');
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/unit/I18N/core/NumberFormatTest.php b/tests/unit/I18N/core/NumberFormatTest.php
index af6a06ca..e136058e 100644
--- a/tests/unit/I18N/core/NumberFormatTest.php
+++ b/tests/unit/I18N/core/NumberFormatTest.php
@@ -12,6 +12,7 @@ class NumberFormatTest extends PHPUnit2_Framework_TestCase {
$formatter = new NumberFormat();
$number = '123456789.125156';
$wanted = '123,456,789.125156';
+
$this->assertEquals($wanted, $formatter->format($number));
//currency
@@ -87,8 +88,7 @@ class NumberFormatTest extends PHPUnit2_Framework_TestCase {
$pattern = '0000';
$wanted = '0005';
- //this should fail!!!
- $this->assertNotEquals($wanted, $formatter->format($number, $pattern));
+ $this->assertEquals($wanted, $formatter->format($number, $pattern));
}
function testFormatWithANegativeValue() {
@@ -105,7 +105,28 @@ class NumberFormatTest extends PHPUnit2_Framework_TestCase {
$expected = "10E";
$this->assertEquals('10E', $formatter->format($number, 'e'));
}
+
+ function testRounding()
+ {
+ $formatter = new NumberFormat();
+
+ $number = 349.999;
+ $pattern = '#.00';
+ $expected = '350.00';
+
+ $this->assertEquals($expected, $formatter->format($number, $pattern));
+ }
+ function testRounding2()
+ {
+ $formatter = new NumberFormat();
+
+ $number = 349.99;
+ $pattern = '#.00';
+ $expected = '349.99';
+
+ $this->assertEquals($expected, $formatter->format($number, $pattern));
+ }
}
?> \ No newline at end of file