*/
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;
}
};
* @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;
},
/**
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.
*
* @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));
+ }
}
}
public static function formatInteger($integer) {
$integer = self::addThousandsSeparator($integer);
+ // format minus
+ $integer = self::formatNegative($integer);
+
return $integer;
}
// add thousands separator
$double = self::addThousandsSeparator($double);
+ // format minus
+ $double = self::formatNegative($double);
+
return $double;
}
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.
*