const int SingleDefPrecision = 7;
const int DoubleDefPrecision = 15;
- const int Int8DefPrecision = 3;
- const int UInt8DefPrecision = 3;
- const int Int16DefPrecision = 5;
- const int UInt16DefPrecision = 5;
const int Int32DefPrecision = 10;
const int UInt32DefPrecision = 10;
const int Int64DefPrecision = 19;
// Parse the given format and initialize the following fields:
// _isCustomFormat, _specifierIsUpper, _specifier & _precision.
- public NumberFormatter (Thread current)
+ NumberFormatter (Thread current)
{
_cbuf = EmptyArray<char>.Value;
if (current == null)
private void InitHex (ulong value)
{
switch (_defPrecision) {
- case Int8DefPrecision: value = (byte) value; break;
- case Int16DefPrecision: value = (ushort) value; break;
case Int32DefPrecision: value = (uint) value; break;
}
_val1 = (uint)value;
return NumberFormatInfo.GetInstance (fp);
}
- public CultureInfo CurrentCulture {
+ CultureInfo CurrentCulture {
set {
if (value != null && value.IsReadOnly)
_nfi = value.NumberFormat;
threadNumberFormatter = this;
}
- public static string NumberToString (string format, sbyte value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- inst.Init (format, value, Int8DefPrecision);
- string res = inst.IntegerToString (format, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (string format, byte value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- inst.Init (format, value, UInt8DefPrecision);
- string res = inst.IntegerToString (format, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (string format, ushort value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- inst.Init (format, value, Int16DefPrecision);
- string res = inst.IntegerToString (format, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (string format, short value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- inst.Init (format, value, UInt16DefPrecision);
- string res = inst.IntegerToString (format, fp);
- inst.Release();
- return res;
- }
-
public static string NumberToString (string format, uint value, IFormatProvider fp)
{
NumberFormatter inst = GetInstance (fp);
return res;
}
- public static string NumberToString (uint value, IFormatProvider fp)
- {
- if (value >= HundredMillion)
- return NumberToString (null, value, fp);
-
- NumberFormatter inst = GetInstance (fp);
- string res = inst.FastIntegerToString ((int)value, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (int value, IFormatProvider fp)
- {
- if (value >= HundredMillion || value <= -HundredMillion)
- return NumberToString (null, value, fp);
-
- NumberFormatter inst = GetInstance (fp);
- string res = inst.FastIntegerToString (value, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (ulong value, IFormatProvider fp)
- {
- if (value >= HundredMillion)
- return NumberToString (null, value, fp);
-
- NumberFormatter inst = GetInstance (fp);
- string res = inst.FastIntegerToString ((int)value, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (long value, IFormatProvider fp)
- {
- if (value >= HundredMillion || value <= -HundredMillion)
- return NumberToString (null, value, fp);
-
- NumberFormatter inst = GetInstance (fp);
- string res = inst.FastIntegerToString ((int)value, fp);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (float value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- inst.Init (null, value, SingleDefPrecision);
- NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
- string res;
- if (inst._NaN)
- res = nfi.NaNSymbol;
- else if (inst._infinity)
- if (inst._positive)
- res = nfi.PositiveInfinitySymbol;
- else
- res = nfi.NegativeInfinitySymbol;
- else
- res = inst.FormatGeneral (-1, nfi);
- inst.Release();
- return res;
- }
-
- public static string NumberToString (double value, IFormatProvider fp)
- {
- NumberFormatter inst = GetInstance (fp);
- NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
- inst.Init (null, value, DoubleDefPrecision);
- string res;
- if (inst._NaN)
- res = nfi.NaNSymbol;
- else if (inst._infinity)
- if (inst._positive)
- res = nfi.PositiveInfinitySymbol;
- else
- res = nfi.NegativeInfinitySymbol;
- else
- res = inst.FormatGeneral (-1, nfi);
- inst.Release();
- return res;
- }
-
private string FastIntegerToString (int value, IFormatProvider fp)
{
if (value < 0) {
}
}
- public string FormatCurrency (int precision, NumberFormatInfo nfi)
+ string FormatCurrency (int precision, NumberFormatInfo nfi)
{
precision = (precision >= 0 ? precision : nfi.CurrencyDecimalDigits);
RoundDecimal (precision);
return new string (_cbuf, 0, _ind);
}
- public string FormatFixedPoint (int precision, NumberFormatInfo nfi)
+ string FormatFixedPoint (int precision, NumberFormatInfo nfi)
{
if (precision == -1)
precision = nfi.NumberDecimalDigits;
return new string (_cbuf, 0, _ind);
}
- public string FormatNumber (int precision, NumberFormatInfo nfi)
+ string FormatNumber (int precision, NumberFormatInfo nfi)
{
precision = (precision >= 0 ? precision : nfi.NumberDecimalDigits);
ResetCharBuf (IntegerDigits * 3 + precision);
return new string (_cbuf, 0, _ind);
}
- public string FormatPercent (int precision, NumberFormatInfo nfi)
+ string FormatPercent (int precision, NumberFormatInfo nfi)
{
precision = (precision >= 0 ? precision : nfi.PercentDecimalDigits);
Multiply10(2);
return new string (_cbuf, 0, _ind);
}
- public string FormatExponential (int precision, NumberFormatInfo nfi)
+ string FormatExponential (int precision, NumberFormatInfo nfi)
{
if (precision == -1)
precision = DefaultExpPrecision;
return new string (_cbuf, 0, _ind);
}
- public string FormatCustom (string format, NumberFormatInfo nfi)
+ string FormatCustom (string format, NumberFormatInfo nfi)
{
bool p = _positive;
int offset = 0;