Index: trunk/phase3/tests/phpunit/languages/LanguageMlTest.php |
— | — | @@ -26,5 +26,7 @@ |
27 | 27 | $this->assertEquals( '12,345.56', $this->lang->formatNum( '12345.56' ) ); |
28 | 28 | $this->assertEquals( '12,34,56,79,81,23,45,678', $this->lang->formatNum( '12345679812345678' ) ); |
29 | 29 | $this->assertEquals( '.12345', $this->lang->formatNum( '.12345' ) ); |
| 30 | + $this->assertEquals( '-12,00,000', $this->lang->formatNum( '-1200000' ) ); |
| 31 | + $this->assertEquals( '-98', $this->lang->formatNum( '-98' ) ); |
30 | 32 | } |
31 | 33 | } |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -2722,6 +2722,12 @@ |
2723 | 2723 | return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
2724 | 2724 | } else { |
2725 | 2725 | // Ref: http://cldr.unicode.org/translation/number-patterns |
| 2726 | + $sign = ""; |
| 2727 | + if ( intval( $_ ) < 0 ) { |
| 2728 | + // For negative numbers apply the algorithm like positive number and add sign. |
| 2729 | + $sign = $_[0]; |
| 2730 | + $_ = substr( $_,1 ); |
| 2731 | + } |
2726 | 2732 | $numberpart = array(); |
2727 | 2733 | $decimalpart = array(); |
2728 | 2734 | $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches ); |
— | — | @@ -2730,7 +2736,7 @@ |
2731 | 2737 | $groupedNumber = ( count( $decimalpart ) > 0 ) ? $decimalpart[0]:""; |
2732 | 2738 | if ( $groupedNumber === $_ ) { |
2733 | 2739 | // the string does not have any number part. Eg: .12345 |
2734 | | - return $groupedNumber; |
| 2740 | + return $sign . $groupedNumber; |
2735 | 2741 | } |
2736 | 2742 | $start = $end = strlen( $numberpart[0] ); |
2737 | 2743 | while ( $start > 0 ) { |
— | — | @@ -2750,7 +2756,7 @@ |
2751 | 2757 | $groupedNumber = "," . $groupedNumber; |
2752 | 2758 | } |
2753 | 2759 | } |
2754 | | - return $groupedNumber; |
| 2760 | + return $sign . $groupedNumber; |
2755 | 2761 | } |
2756 | 2762 | } |
2757 | 2763 | /** |