Use proper UTF-8 MINUS SIGN
authorTim Düsterhus <duesterhus@woltlab.com>
Sat, 27 Apr 2013 14:44:01 +0000 (16:44 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sat, 27 Apr 2013 14:44:01 +0000 (16:44 +0200)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/util/StringUtil.class.php

index bb51ceb9de98341a361094a6fe3507859807445d..055999c62fae0a16fd6501b82f88c6440a69cf38 100755 (executable)
@@ -2934,16 +2934,16 @@ WCF.MultipleLanguageInput = Class.extend({
  */
 WCF.Number = {
        /**
-        * Rounds a number to a given number of floating points digits. Defaults to 0.
+        * Rounds a number to a given number of decimal places. Defaults to 0.
         * 
         * @param       number          number
-        * @param       floatingPoint   number of digits
+        * @param       decimalPlaces   number of decimal places
         * @return      number
         */
-       round: function (number, floatingPoint) {
-               floatingPoint = Math.pow(10, (floatingPoint || 0));
+       round: function (number, decimalPlaces) {
+               decimalPlaces = Math.pow(10, (decimalPlaces || 0));
                
-               return Math.round(number * floatingPoint) / floatingPoint;
+               return Math.round(number * decimalPlaces) / decimalPlaces;
        }
 };
 
@@ -2988,11 +2988,14 @@ WCF.String = {
         * @param       mixed   number
         * @return      string
         */
-       formatNumeric: function(number, floatingPoint) {
-               number = String(WCF.Number.round(number, floatingPoint || 2));
+       formatNumeric: function(number, decimalPlaces) {
+               number = String(WCF.Number.round(number, decimalPlaces || 2));
                number = number.replace('.', WCF.Language.get('wcf.global.decimalPoint'));
                
-               return this.addThousandsSeparator(number);
+               number = this.addThousandsSeparator(number);
+               number = number.replace('-', '\u2212');
+               
+               return number;
        },
        
        /**
index 6e483cc856521912bf49e382e631908dc542e558..d042630a9d9007c3394dea9831c478e37496c331 100644 (file)
@@ -21,11 +21,17 @@ final class StringUtil {
        const HTML_COMMENT_PATTERN = '~<!--(.*?)-->~';
        
        /**
-        * utf8 bytes of the horizontal ellipsis char
+        * utf8 bytes of the HORIZONTAL ELLIPSIS (U+2026)
         * @var string
         */
        const HELLIP = "\xE2\x80\xA6";
        
+       /**
+        * utf8 bytes of the MINUS SIGN (U+2212)
+        * @var string
+        */
+       const MINUS = "\xE2\x88\x92";
+       
        /**
         * Alias to php sha1() function.
         * 
@@ -141,17 +147,19 @@ final class StringUtil {
         * @return      string
         */
        public static function formatNumeric($numeric) {
-               if (is_int($numeric)) 
+               if (is_int($numeric)) {
                        return self::formatInteger($numeric);
-                       
-               else if (is_float($numeric))
+               }
+               else if (is_float($numeric)) {
                        return self::formatDouble($numeric);
-                       
+               }
                else {
-                       if (floatval($numeric) - (float) intval($numeric))
+                       if (floatval($numeric) - (float) intval($numeric)) {
                                return self::formatDouble($numeric);
-                       else 
+                       }
+                       else {
                                return self::formatInteger(intval($numeric));
+                       }
                }
        }
        
@@ -164,6 +172,9 @@ final class StringUtil {
        public static function formatInteger($integer) {
                $integer = self::addThousandsSeparator($integer);
                
+               // format minus
+               $integer = self::formatNegative($integer);
+               
                return $integer;
        }
        
@@ -192,6 +203,9 @@ final class StringUtil {
                // add thousands separator
                $double = self::addThousandsSeparator($double);
                
+               // format minus
+               $double = self::formatNegative($double);
+               
                return $double;
        }
        
@@ -209,6 +223,16 @@ final class StringUtil {
                return $number;
        }
        
+       /**
+        * Replaces the MINUS-HYPHEN with the MINUS SIGN
+        * 
+        * @param       mixed           $number
+        * @return      string
+        */
+       public static function formatNegative($number) {
+               return self::replace('-', self::MINUS, $number);
+       }
+       
        /**
         * Sorts an array of strings and maintain index association.
         *