當前位置: 首頁>>代碼示例>>C#>>正文


C# Globalization.NumberFormatInfo類代碼示例

本文整理匯總了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();
        }
開發者ID:Saroko-dnd,項目名稱:My_DZ,代碼行數:31,代碼來源:Program.cs

示例2: StringBuilderExtensions

 static StringBuilderExtensions()
 {
     if (m_numberFormatInfoHelper == null)
     {
         m_numberFormatInfoHelper = CultureInfo.InvariantCulture.NumberFormat.Clone() as NumberFormatInfo;
     }
 }
開發者ID:Krulac,項目名稱:SpaceEngineers,代碼行數:7,代碼來源:StringBuilderExtensions.cs

示例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;
			}
		}
開發者ID:thekindofme,項目名稱:.netcf-Validation-Framework,代碼行數:31,代碼來源:NumberConversionRule.cs

示例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);
	}
開發者ID:salloo,項目名稱:mono,代碼行數:34,代碼來源:IntegerFormatterTest.cs

示例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;
		}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:35,代碼來源:DoubleFormatterTest.cs

示例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);
            }
        }
開發者ID:joyanta,項目名稱:lucene.net,代碼行數:28,代碼來源:TestWildcardRandom.cs

示例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
			}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:34,代碼來源:SingleType.cs

示例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;
			}
		}
開發者ID:bradparks,項目名稱:DotNetAnywhere,代碼行數:7,代碼來源:ParseHelper.cs

示例9: BlackBoxFunction

 public BlackBoxFunction()
 {
     provider = new NumberFormatInfo();
     provider.NumberDecimalSeparator = ".";
    /// provider.NumberGroupSeparator = ".";
     provider.NumberGroupSizes = new int[] { 2 };
 }
開發者ID:unn-85m3,項目名稱:project,代碼行數:7,代碼來源:BlackBoxFunction.cs

示例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;
            }
        }
開發者ID:EugeneGudima,項目名稱:Reflecta,代碼行數:32,代碼來源:ACalibrationDatabaseWorker.cs

示例11: FrameRateCounter

 public FrameRateCounter(ScreenManager screenManager)
     : base(screenManager.Game)
 {
     _screenManager = screenManager;
     _format = new NumberFormatInfo();
     _format.NumberDecimalSeparator = ".";
 }
開發者ID:liwq-net,項目名稱:SilverSprite,代碼行數:7,代碼來源:FramerateCounterComponent.cs

示例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);
 }
開發者ID:vpuydoyeux,項目名稱:Schmup,代碼行數:11,代碼來源:FrameRateCounter.cs

示例13: ToFloat

        public static float ToFloat(string s)
        {
            NumberFormatInfo _NumberFormatInfo = new NumberFormatInfo();
            _NumberFormatInfo.NumberDecimalSeparator = ".";

            return float.Parse(s,_NumberFormatInfo);
        }
開發者ID:aniPerezG,項目名稱:barbalpha,代碼行數:7,代碼來源:Q3ShaderParser.cs

示例14: ToString

        public static string ToString(float f)
        {
            NumberFormatInfo _NumberFormatInfo = new NumberFormatInfo();
            _NumberFormatInfo.NumberDecimalSeparator = ".";

            return f.ToString(_NumberFormatInfo);
        }
開發者ID:aniPerezG,項目名稱:barbalpha,代碼行數:7,代碼來源:Q3ShaderParser.cs

示例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;
 }
開發者ID:wenwu704341771,項目名稱:MyHelper,代碼行數:12,代碼來源:MyStringHelper.cs


注:本文中的System.Globalization.NumberFormatInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。