UEA-PRODEM
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ export default function(x) {
|
||||
// significant digits p, where x is positive and p is in [1, 21] or undefined.
|
||||
// For example, formatDecimalParts(1.23) returns ["123", 0].
|
||||
export function formatDecimalParts(x, p) {
|
||||
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
|
||||
var i, coefficient = x.slice(0, i);
|
||||
if (!isFinite(x) || x === 0) return null; // NaN, ±Infinity, ±0
|
||||
var i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e"), coefficient = x.slice(0, i);
|
||||
|
||||
// The string returned by toExponential either has the form \d\.\d+e[-+]\d+
|
||||
// (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ export var prefixExponent;
|
||||
|
||||
export default function(x, p) {
|
||||
var d = formatDecimalParts(x, p);
|
||||
if (!d) return x + "";
|
||||
if (!d) return prefixExponent = undefined, x.toPrecision(p);
|
||||
var coefficient = d[0],
|
||||
exponent = d[1],
|
||||
i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
||||
|
||||
+7
-8
@@ -20,7 +20,7 @@ export default function(locale) {
|
||||
minus = locale.minus === undefined ? "−" : locale.minus + "",
|
||||
nan = locale.nan === undefined ? "NaN" : locale.nan + "";
|
||||
|
||||
function newFormat(specifier) {
|
||||
function newFormat(specifier, options) {
|
||||
specifier = formatSpecifier(specifier);
|
||||
|
||||
var fill = specifier.fill,
|
||||
@@ -45,8 +45,8 @@ export default function(locale) {
|
||||
|
||||
// Compute the prefix and suffix.
|
||||
// For SI-prefix, the suffix is lazily computed.
|
||||
var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
|
||||
suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
|
||||
var prefix = (options && options.prefix !== undefined ? options.prefix : "") + (symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : ""),
|
||||
suffix = (symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "") + (options && options.suffix !== undefined ? options.suffix : "");
|
||||
|
||||
// What format function should we use?
|
||||
// Is this an integer type?
|
||||
@@ -87,7 +87,7 @@ export default function(locale) {
|
||||
|
||||
// Compute the prefix and suffix.
|
||||
valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
|
||||
valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
|
||||
valueSuffix = (type === "s" && !isNaN(value) && prefixExponent !== undefined ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
|
||||
|
||||
// Break the formatted value into the integer “value” part that can be
|
||||
// grouped, and fractional or exponential “suffix” part that is not.
|
||||
@@ -132,12 +132,11 @@ export default function(locale) {
|
||||
}
|
||||
|
||||
function formatPrefix(specifier, value) {
|
||||
var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
|
||||
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
|
||||
var e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
|
||||
k = Math.pow(10, -e),
|
||||
prefix = prefixes[8 + e / 3];
|
||||
f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier), {suffix: prefixes[8 + e / 3]});
|
||||
return function(value) {
|
||||
return f(k * value) + prefix;
|
||||
return f(k * value);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user