本文整理汇总了C#中System.Globalization.NumberFormatInfo类的典型用法代码示例。如果您正苦于以下问题:C# NumberFormatInfo类的具体用法?C# NumberFormatInfo怎么用?C# NumberFormatInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberFormatInfo类属于System.Globalization命名空间,在下文中一共展示了NumberFormatInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// установка разделитя в дробных суммах (зависит от настройки локализации)
NumberFormatInfo formatSepar = new NumberFormatInfo();
formatSepar.NumberDecimalSeparator = ".";
// Загрузка документа в память
XDocument xmlDoc = XDocument.Load("books.xml");
IEnumerable<XElement> books = xmlDoc.Root.Elements("book")
.Where(t => t.Element("genre").Value == "Computer");
// XDocument.Descendants(XName)
// Возвращает коллекцию подчиненных узлов для данного элемента.
// Только элементы, имеющие соответствующее XName, включаются в коллекцию.
//IEnumerable<XElement> books = xmlDoc.Root.Descendants("book")
// .Where(t => t.Element("genre").Value == "Computer");
books.Remove();
xmlDoc.Save("booksNew.xml");
Console.WriteLine("Удаление выполнено успешно...");
Console.ReadKey();
}
示例2: StringBuilderExtensions
static StringBuilderExtensions()
{
if (m_numberFormatInfoHelper == null)
{
m_numberFormatInfoHelper = CultureInfo.InvariantCulture.NumberFormat.Clone() as NumberFormatInfo;
}
}
示例3: NumberConversionRule
/// <param name="typeCode">The <see cref="TypeCode"/> that this <see cref="NumberConversionRule"/> attempts to convert to.</param>
public NumberConversionRule(TypeCode typeCode)
: base(TypePointers.StringType)
{
if ((typeCode == TypeCode.String) || (typeCode == TypeCode.DateTime))
{
throw new ArgumentException("datatype cannot be String or DateTime.", "typeCode");
}
TypeCode = typeCode;
numberFormatInfo = NumberFormatInfo.CurrentInfo;
switch (typeCode)
{
case TypeCode.Decimal:
NumberStyles = NumberStyles.Number;
break;
case TypeCode.Double:
case TypeCode.Single:
NumberStyles = NumberStyles.Float | NumberStyles.AllowThousands;
break;
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
NumberStyles = NumberStyles.Integer;
break;
}
}
示例4: ProcessLine
private void ProcessLine (string testLine, NumberFormatInfo nfi)
{
string number = "0";
string format = "X";
string expected = "XXX";
int idxStart;
int idxEnd;
idxStart = testLine.IndexOf ('(');
if (idxStart != -1){
idxStart++;
idxEnd = testLine.IndexOf (')');
number = testLine.Substring (idxStart,
idxEnd - idxStart);
}
idxStart = testLine.IndexOf ('(', idxStart);
if (idxStart != -1) {
idxStart++;
idxEnd = testLine.IndexOf (')', idxStart);
format = testLine.Substring (idxStart,
idxEnd - idxStart);
}
idxStart = testLine.IndexOf ('(', idxStart);
if (idxStart != -1) {
idxStart++;
idxEnd = testLine.LastIndexOf (')');
expected = testLine.Substring (idxStart,
idxEnd - idxStart);
}
DoTest (number, format, expected, nfi);
}
示例5: GetNumberFormat2
private NumberFormatInfo GetNumberFormat2()
{
NumberFormatInfo format = new NumberFormatInfo();
format.NaNSymbol = "Geen";
format.PositiveSign = "+";
format.NegativeSign = "-";
format.PerMilleSymbol = "x";
format.PositiveInfinitySymbol = "Oneindig";
format.NegativeInfinitySymbol = "-Oneindig";
format.NumberDecimalDigits = 2;
format.NumberDecimalSeparator = ".";
format.NumberGroupSeparator = ",";
format.NumberGroupSizes = new int[] {3};
format.NumberNegativePattern = 1;
format.CurrencyDecimalDigits = 1;
format.CurrencyDecimalSeparator = ".";
format.CurrencyGroupSeparator = ",";
format.CurrencyGroupSizes = new int[] {3};
format.CurrencyNegativePattern = 3;
format.CurrencyPositivePattern = 1;
format.CurrencySymbol = "$";
format.PercentDecimalDigits = 2;
format.PercentDecimalSeparator = ".";
format.PercentGroupSeparator = ",";
format.PercentGroupSizes = new int[] {3};
format.PercentNegativePattern = 1;
format.PercentPositivePattern = 2;
format.PercentSymbol = "##";
return format;
}
示例6: SetUp
public override void SetUp()
{
base.SetUp();
Dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000)));
Document doc = new Document();
Field field = NewStringField("field", "", Field.Store.NO);
doc.Add(field);
NumberFormatInfo df = new NumberFormatInfo();
df.NumberDecimalDigits = 0;
//NumberFormat df = new DecimalFormat("000", new DecimalFormatSymbols(Locale.ROOT));
for (int i = 0; i < 1000; i++)
{
field.StringValue = i.ToString(df);
writer.AddDocument(doc);
}
Reader = writer.Reader;
Searcher = NewSearcher(Reader);
writer.Dispose();
if (VERBOSE)
{
Console.WriteLine("TEST: setUp searcher=" + Searcher);
}
}
示例7: FromString
public static float FromObject
(Object Value, NumberFormatInfo NumberFormat)
{
#if !ECMA_COMPAT
if(Value != null)
{
IConvertible ic = (Value as IConvertible);
if(ic != null)
{
if(ic.GetTypeCode() != TypeCode.String)
{
return ic.ToSingle(NumberFormat);
}
else
{
return FromString(ic.ToString(null), NumberFormat);
}
}
else
{
throw new InvalidCastException
(String.Format
(S._("VB_InvalidCast"),
Value.GetType(), "System.Single"));
}
}
else
{
return 0.0f;
}
#else
return (float)(DoubleType.FromObject(Value, NumberFormat));
#endif
}
示例8: FindCurrency
private static void FindCurrency(ref int pos, string s, NumberFormatInfo nfi, ref bool foundCurrency) {
if ((pos + nfi.CurrencySymbol.Length) <= s.Length &&
s.Substring(pos, nfi.CurrencySymbol.Length) == nfi.CurrencySymbol) {
foundCurrency = true;
pos += nfi.CurrencySymbol.Length;
}
}
示例9: BlackBoxFunction
public BlackBoxFunction()
{
provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
/// provider.NumberGroupSeparator = ".";
provider.NumberGroupSizes = new int[] { 2 };
}
示例10: WriteCalibrationGroup
internal static int WriteCalibrationGroup(ADatabase db, int average, double firmware, string serial)
{
try
{
NumberFormatInfo formatInfo = new NumberFormatInfo();
formatInfo.NumberDecimalSeparator = ".";
string sql = "INSERT INTO CalibrationGroup (NumOfAverage, Datetime, SensorSerial, SensorFirmware) VALUES (" + average.ToString() + ",'" + DateTime.Now.ToString("dd.MM.yy HH:mm:ss.ff") + "', '" + serial + "', " + firmware.ToString(formatInfo) + ")";
NpgsqlCommand command = new NpgsqlCommand(sql, db.Connection);
command.ExecuteNonQuery();
sql = "SELECT currval(pg_get_serial_sequence('CalibrationGroup', 'calibrationgroupid'));";
command = new NpgsqlCommand(sql, db.Connection);
NpgsqlDataReader myreader = command.ExecuteReader();
if (myreader.Read())
{
int result = Convert.ToInt32(myreader[0].ToString());
myreader.Close();
return result;
}
else
{
myreader.Close();
return -1;
}
}
catch (Exception ex)
{
FileWorker.WriteEventFile(DateTime.Now, "ACalibrationDatabaseWorker", "WriteCalibrationGroup", ex.Message);
return -1;
}
}
示例11: FrameRateCounter
public FrameRateCounter(ScreenManager screenManager)
: base(screenManager.Game)
{
_screenManager = screenManager;
_format = new NumberFormatInfo();
_format.NumberDecimalSeparator = ".";
}
示例12: FrameRateCounter
/// <summary>
/// Initialize a new instance of FrameRateCounter
/// </summary>
/// <param name="game">The game</param>
public FrameRateCounter(Game game)
: base(game)
{
format = new NumberFormatInfo();
format.NumberDecimalSeparator = ".";
position = new Vector2(5, 5);
}
示例13: ToFloat
public static float ToFloat(string s)
{
NumberFormatInfo _NumberFormatInfo = new NumberFormatInfo();
_NumberFormatInfo.NumberDecimalSeparator = ".";
return float.Parse(s,_NumberFormatInfo);
}
示例14: ToString
public static string ToString(float f)
{
NumberFormatInfo _NumberFormatInfo = new NumberFormatInfo();
_NumberFormatInfo.NumberDecimalSeparator = ".";
return f.ToString(_NumberFormatInfo);
}
示例15: TransformPrice
/// <summary>
/// 把价格精确至小数点两位
/// </summary>
/// <param name="dPrice">价格</param>
/// <returns>返回值</returns>
public static string TransformPrice(double dPrice)
{
double d = dPrice;
var myNfi = new NumberFormatInfo { NumberNegativePattern = 2 };
string s = d.ToString("N", myNfi);
return s;
}