本文整理汇总了C#中NumberStyles类的典型用法代码示例。如果您正苦于以下问题:C# NumberStyles类的具体用法?C# NumberStyles怎么用?C# NumberStyles使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberStyles类属于命名空间,在下文中一共展示了NumberStyles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static int Parse(string s, NumberStyles style)
{
if (style == NumberStyles.HexNumber)
return Native.API.intval(s, 16);
return Native.API.intval(s);
}
示例2: Parse
public static ulong Parse(String s, NumberStyles style,
IFormatProvider provider)
{
NumberParser.ValidateIntegerStyle(style);
return NumberParser.ParseUInt64
(s, style, NumberFormatInfo.GetInstance(provider), 0);
}
示例3: TryParse
public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out sbyte result)
{
// Todo, consider how to implemente style and provider
throw new NotImplementedException();
//return TryParse(s, out result);
}
示例4: Parse
// Parsing methods.
public static byte Parse(String s, NumberStyles style,
IFormatProvider provider)
{
NumberParser.ValidateIntegerStyle(style);
return Convert.ToByte(NumberParser.ParseUInt32
(s, style, NumberFormatInfo.GetInstance(provider), 256));
}
示例5: ccParseInt
/// <summary>
/// Parses aint value for the given string using the given number style and using
/// the invariant culture parser.
/// </summary>
/// <param name="toParse">The value to parse.</param>
/// <param name="ns">The number style used to parse the int value.</param>
/// <returns>The int value of the string.</returns>
public static int ccParseInt(string toParse, NumberStyles ns)
{
// http://www.cocos2d-x.org/boards/17/topics/11690
// Issue #17
// https://github.com/cocos2d/cocos2d-x-for-xna/issues/17
return (int.Parse(toParse, ns, System.Globalization.CultureInfo.InvariantCulture));
}
示例6: CheckStyle
private static bool CheckStyle(NumberStyles style, bool tryParse, ref Exception exc)
{
if ((style & NumberStyles.AllowHexSpecifier) != 0)
{
NumberStyles ne = style ^ NumberStyles.AllowHexSpecifier;
if ((ne & NumberStyles.AllowLeadingWhite) != 0)
{
ne ^= NumberStyles.AllowLeadingWhite;
}
if ((ne & NumberStyles.AllowTrailingWhite) != 0)
{
ne ^= NumberStyles.AllowTrailingWhite;
}
if (ne != 0)
{
if (!tryParse)
{
exc = new ArgumentException(
"With AllowHexSpecifier only " +
"AllowLeadingWhite and AllowTrailingWhite " +
"are permitted.");
}
return false;
}
}
return true;
}
示例7: Parse
// Parsing methods.
public static short Parse(String s, NumberStyles style,
IFormatProvider provider)
{
NumberParser.ValidateIntegerStyle(style);
return Convert.ToInt16(NumberParser.ParseInt32
(s, style, NumberFormatInfo.GetInstance(provider), 32768));
}
示例8: TryParseDecimal
/// <summary>
/// Tries to convert a string representation into a numeric value.
/// </summary>
public static bool TryParseDecimal(string s, NumberStyles style, out decimal result)
{
#if PocketPC
try
{
result = decimal.Parse(s, style, CultureInfo.InvariantCulture);
return true;
}
catch (ArgumentException)
{
result = Decimal.Zero;
return false;
}
catch (FormatException)
{
result = Decimal.Zero;
return false;
}
catch (OverflowException)
{
result = Decimal.Zero;
return false;
}
#else
return decimal.TryParse(s, style, CultureInfo.InvariantCulture, out result);
#endif
}
示例9: IsNumeric
public static bool IsNumeric(this string text, NumberStyles style = NumberStyles.Number, CultureInfo culture = null)
{
double number;
if (culture == null)
culture = CultureInfo.InvariantCulture;
return double.TryParse(text, style, culture, out number) && !string.IsNullOrWhiteSpace(text);
}
示例10: ParseTest
public ParseTest(String str, Decimal d, NumberStyles style)
{
this.str = str;
this.exceptionFlag = false;
this.style = style;
this.d = d;
}
示例11: InitializeMembers
private void InitializeMembers()
{
this.encoding = null;
this.culture = null;
this.numberStyle = NumberStyles.Float;
this.dateTimeStyle = DateTimeStyles.None;
}
示例12: ConvertToNumeric
public static Double ConvertToNumeric(object value, IFormatProvider provider, NumberStyles style)
{
var parsableString = value as String;
if (parsableString == null)
{
var formatter = value as IFormattable;
if (formatter != null)
{
string format = GeneralFormatter;
if (formatter is Single || formatter is Double)
{
format = RoundtripFormatter;
}
parsableString = formatter.ToString(format, provider);
}
}
if (parsableString != null)
{
Double number;
if (Double.TryParse(parsableString, style, provider, out number))
{
return number;
}
}
throw new FormatException(Resources.Converter_Value_cant_be_parsed_to_numeric);
}
示例13: Parse
/// <summary>Converts the string representation of a money value to its <see cref="Money"/> equivalent.</summary>
/// <param name="value">The string representation of the number to convert.</param>
/// <param name="style">A bitwise combination of enumeration values that indicates the permitted format of value. A typical value to specify is <see cref="NumberStyles.Currency"/>.</param>
/// <param name="provider">An object that supplies culture-specific parsing information about <i>value</i>.</param>
/// <param name="currency">The currency to use for parsing the string representation.</param>
/// <returns>The equivalent to the money amount contained in <i>value</i>.</returns>
/// <exception cref="System.ArgumentNullException"><i>value</i> is <b>null</b> or empty.</exception>
/// <exception cref="System.FormatException"><i>value</i> is not in the correct format or the currency sign matches with multiple known currencies!</exception>
/// <exception cref="System.OverflowException"><i>value</i> represents a number less than <see cref="Decimal.MinValue"/> or greater than <see cref="Decimal.MaxValue"/>.</exception>
public static Money Parse(string value, NumberStyles style, IFormatProvider provider, Currency currency)
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentNullException(nameof(value));
decimal amount = decimal.Parse(value, style, GetNumberFormatInfo(currency, provider));
return new Money(amount, currency);
}
示例14: CsvColumnAttribute
public CsvColumnAttribute(string name, int fieldIndex, bool canBeNull,
string outputFormat, NumberStyles numberStyle, int charLength)
: base(name, fieldIndex, canBeNull)
{
NumberStyle = numberStyle;
OutputFormat = outputFormat;
CharLength = charLength;
}
示例15: Parse
/// <summary>
/// Mono does not support the BigInteger.TryParse method. In practice,
/// we seldom actually need to parse huge integers, so it makes sense
/// to support most real-life cases by simply trying to parse using
/// Int64, and only falling back if needed.
/// </summary>
internal static BigInteger Parse(string str, NumberStyles style) {
UInt64 parsed;
if (UInt64.TryParse(str, style, NumberFormatInfo.CurrentInfo, out parsed)) {
return new BigInteger(parsed);
} else {
// Throws on Mono 3.2.8
return BigInteger.Parse(str, style);
}
}