From 7e969bc772b79082c03b29420a9ba7d8197c4253 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 27 Apr 2013 16:44:01 +0200 Subject: [PATCH] Use proper UTF-8 MINUS SIGN --- wcfsetup/install/files/js/WCF.js | 19 ++++++---- .../files/lib/util/StringUtil.class.php | 38 +++++++++++++++---- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index bb51ceb9de..055999c62f 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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; }, /** diff --git a/wcfsetup/install/files/lib/util/StringUtil.class.php b/wcfsetup/install/files/lib/util/StringUtil.class.php index 6e483cc856..d042630a9d 100644 --- a/wcfsetup/install/files/lib/util/StringUtil.class.php +++ b/wcfsetup/install/files/lib/util/StringUtil.class.php @@ -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. * -- 2.20.1