📄 scriptresource(2).axd
字号:
if (e) throw e;
return Number._parse(value, Sys.CultureInfo.CurrentCulture);
}
Number.parseInvariant = function Number$parseInvariant(value) {
/// <summary locid="M:J#Number.parseInvariant" />
/// <param name="value" type="String"></param>
/// <returns type="Number"></returns>
var e = Function._validateParams(arguments, [
{name: "value", type: String}
]);
if (e) throw e;
return Number._parse(value, Sys.CultureInfo.InvariantCulture);
}
Number._parse = function Number$_parse(value, cultureInfo) {
// <param name="value" type="String">A string that can parse to a number.</param>
// <param name="cultureInfo" type="Sys.CultureInfo">Culture information.</param>
// <returns type="Number">Parsed number or Number.NaN if parsing failed.</returns>
value = value.trim();
// allow infinity or hexidecimal for javascript compatability.
if (value.match(/^[+-]?infinity$/i)) {
return parseFloat(value);
}
if (value.match(/^0x[a-f0-9]+$/i)) {
return parseInt(value);
}
var numFormat = cultureInfo.numberFormat;
var signInfo = Number._parseNumberNegativePattern(value, numFormat, numFormat.NumberNegativePattern);
var sign = signInfo[0];
var num = signInfo[1];
// support leading sign without space in addition to culture negative format for .NET compatability
if ((sign === '') && (numFormat.NumberNegativePattern !== 1)) {
signInfo = Number._parseNumberNegativePattern(value, numFormat, 1);
sign = signInfo[0];
num = signInfo[1];
}
if (sign === '') sign = '+';
var exponent;
var intAndFraction;
var exponentPos = num.indexOf('e');
if (exponentPos < 0) exponentPos = num.indexOf('E');
if (exponentPos < 0) {
intAndFraction = num;
exponent = null;
}
else {
intAndFraction = num.substr(0, exponentPos);
exponent = num.substr(exponentPos + 1);
}
var integer;
var fraction;
var decimalPos = intAndFraction.indexOf(numFormat.NumberDecimalSeparator);
if (decimalPos < 0) {
integer = intAndFraction;
fraction = null;
}
else {
integer = intAndFraction.substr(0, decimalPos);
fraction = intAndFraction.substr(decimalPos + numFormat.NumberDecimalSeparator.length);
}
// strip group separators from the integer portion
integer = integer.split(numFormat.NumberGroupSeparator).join('');
var p = sign + integer;
if (fraction !== null) {
p += '.' + fraction;
}
if (exponent !== null) {
var expSignInfo = Number._parseNumberNegativePattern(exponent, numFormat, 1);
if (expSignInfo[0] === '') {
expSignInfo[0] = '+';
}
p += 'e' + expSignInfo[0] + expSignInfo[1];
}
// don't allow multiple decimals separators, group separators after decimal or trailing strings.
if (p.match(/^[+-]?\d*\.?\d*(e[+-]?\d+)?$/)) {
return parseFloat(p);
}
return Number.NaN;
}
Number._parseNumberNegativePattern = function Number$_parseNumberNegativePattern(value, numFormat, numberNegativePattern) {
// <summary>
// Extracts the sign and number from a numeric input string using the culture-specific number format
// information and number negative pattern.
// </summary>
// <param name="value" type="String">Numerical string value.</param>
// <param name="numFormat" type="Object">Culture-specific number formatting information.</param>
// <param name="numberNegativePattern" type="Number">Culture-specific specifier for the negative number format.
// </param>
// <returns type="Array">Sign and number for the input value. The sign is the invariant symbol or an empty
// string if the number was unsigned.
// </returns>
var neg = numFormat.NegativeSign;
var pos = numFormat.PositiveSign;
switch (numberNegativePattern) {
case 4: // trailing sign with space
neg = ' ' + neg;
pos = ' ' + pos;
case 3: // trailing sign no space
if (value.endsWith(neg)) {
return ['-', value.substr(0, value.length - neg.length)];
}
else if (value.endsWith(pos)) {
return ['+', value.substr(0, value.length - pos.length)];
}
break;
case 2: // leading sign with space
neg += ' ';
pos += ' ';
case 1: // leading sign no space
if (value.startsWith(neg)) {
return ['-', value.substr(neg.length)];
}
else if (value.startsWith(pos)) {
return ['+', value.substr(pos.length)];
}
break;
case 0: // parenthesis
if (value.startsWith('(') && value.endsWith(')')) {
return ['-', value.substr(1, value.length - 2)];
}
break;
}
return ['', value];
}
Number.prototype.format = function Number$format(format) {
/// <summary locid="M:J#Number.format" />
/// <param name="format" type="String"></param>
/// <returns type="String"></returns>
var e = Function._validateParams(arguments, [
{name: "format", type: String}
]);
if (e) throw e;
return this._toFormattedString(format, Sys.CultureInfo.InvariantCulture);
}
Number.prototype.localeFormat = function Number$localeFormat(format) {
/// <summary locid="M:J#Number.localeFormat" />
/// <param name="format" type="String"></param>
/// <returns type="String"></returns>
var e = Function._validateParams(arguments, [
{name: "format", type: String}
]);
if (e) throw e;
return this._toFormattedString(format, Sys.CultureInfo.CurrentCulture);
}
Number.prototype._toFormattedString = function Number$_toFormattedString(format, cultureInfo) {
if (!format || (format.length === 0) || (format === 'i')) {
if (cultureInfo && (cultureInfo.name.length > 0)) {
return this.toLocaleString();
}
else {
return this.toString();
}
}
// All the enum patterns for the various NumberFormats
var _percentPositivePattern = ["n %", "n%", "%n" ];
var _percentNegativePattern = ["-n %", "-n%", "-%n"];
var _numberNegativePattern = ["(n)","-n","- n","n-","n -"];
var _currencyPositivePattern = ["$n","n$","$ n","n $"];
var _currencyNegativePattern = ["($n)","-$n","$-n","$n-","(n$)","-n$","n-$","n$-","-n $","-$ n","n $-","$ n-","$ -n","n- $","($ n)","(n $)"];
// Handles expanding numbers into some specified grouping i.e. [2, 3, 5] would be ...,XXXXX,XXXXX,XXX,XX,
function expandNumber(number, precision, groupSizes, sep, decimalChar) {
var curSize = groupSizes[0];
var curGroupIndex = 1;
// Make the number a string
var numberString = number.toString();
var right = "";
var exponent = "";
// Split: left is integer, right is decimal and exponent.
var decimalSplit = numberString.split('.');
if (decimalSplit.length > 1) {
numberString = decimalSplit[0];
right = decimalSplit[1];
// Split: left is decimal, right is exponent.
var exponentSplit = right.split(/e/i);
if (exponentSplit.length > 1) {
right = exponentSplit[0];
exponent = "e" + exponentSplit[1];
}
}
// now check precision, if its 0, drop right, otherwise reassemble it
if (precision > 0) {
// trim right down to precision size
var rightDifference = right.length - precision;
if (rightDifference > 0) {
right = right.slice(0, precision);
} else if (rightDifference < 0) {
for (var i=0; i<Math.abs(rightDifference); i++) {
right += '0';
}
}
// finally add the separator
right = decimalChar + right;
}
else { // No precision wanted, so drop the right
right = "";
}
right += exponent;
var stringIndex = numberString.length-1;
var ret = "";
while (stringIndex >= 0) {
// group size of 0 or larger than the rest of the string means take the rest of the string
if (curSize === 0 || curSize > stringIndex) {
if (ret.length > 0)
return numberString.slice(0, stringIndex + 1) + sep + ret + right;
else
return numberString.slice(0, stringIndex + 1) + right;
}
if (ret.length > 0)
ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1) + sep + ret;
else
ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1);
stringIndex -= curSize;
if (curGroupIndex < groupSizes.length) {
curSize = groupSizes[curGroupIndex];
curGroupIndex++;
}
}
return numberString.slice(0, stringIndex + 1) + sep + ret + right;
}
var nf = cultureInfo.numberFormat;
// Number is always positive for printing purposes (negative treated separately)
var number = Math.abs(this);
// Default to number format
if (!format)
format = "D";
var precision = -1;
if (format.length > 1) precision = parseInt(format.slice(1), 10);
var pattern;
switch (format.charAt(0)) {
case "d":
case "D":
pattern = 'n';
// precision for decimal is padding
if (precision !== -1) {
var numberStr = ""+number;
var zerosToAdd = precision - numberStr.length;
if (zerosToAdd > 0) {
for (var i=0; i<zerosToAdd; i++) {
numberStr = '0'+numberStr;
}
}
number = numberStr;
}
// We do want the negative for this scenario only
if (this < 0) number = -number;
break;
case "c":
case "C":
if (this < 0) pattern = _currencyNegativePattern[nf.CurrencyNegativePattern];
else pattern = _currencyPositivePattern[nf.CurrencyPositivePattern];
if (precision === -1) precision = nf.CurrencyDecimalDigits;
number = expandNumber(Math.abs(this), precision, nf.CurrencyGroupSizes, nf.CurrencyGroupSeparator, nf.CurrencyDecimalSeparator);
break;
case "n":
case "N":
if (this < 0) pattern = _numberNegativePattern[nf.NumberNegativePattern];
else pattern = 'n';
if (precision === -1) precision = nf.NumberDecimalDigits;
number = expandNumber(Math.abs(this), precision, nf.NumberGroupSizes, nf.NumberGroupSeparator, nf.NumberDecimalSeparator);
break;
case "p":
case "P":
if (this < 0) pattern = _percentNegativePattern[nf.PercentNegativePattern];
else pattern = _percentPositivePattern[nf.PercentPositivePattern];
if (precision === -1) precision = nf.PercentDecimalDigits;
number = expandNumber(Math.abs(this), precision, nf.PercentGroupSizes, nf.PercentGroupSeparator, nf.PercentDecimalSeparator);
break;
default:
throw Error.format(Sys.Res.formatBadFormatSpecifier);
}
var regex = /n|\$|-|%/g;
// Start with an empty string
var ret = "";
for (;;) {
// Save the current index
var index = regex.lastIndex;
// Look for the next pattern
var ar = regex.exec(pattern);
// Append the text before the pattern (or the end of the string if not found)
ret += pattern.slice(index, ar ? ar.index : pattern.length);
if (!ar)
break;
switch (ar[0]) {
case "n":
ret += number;
break;
case "$":
ret += nf.CurrencySymbol;
break;
case "-":
ret += nf.NegativeSign;
break;
case "%":
ret += nf.PercentSymbol;
break;
}
}
return ret;
}
RegExp.__typeName
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -