c# - Convert Standard Numeric Format with culture to Custom Numeric Format -


In C #, is there a way to get a custom numeric format equal to a standard numeric format with a specified user's culture? is?

Example (not sure that my conversion is correct):

  • C3-FR = 0.000 '' '
  • D2 = 0.00 < / Li>
  • P0 =% # 0

See those links:

Given a to get NumberFormat Types of information can be examined by all types of information that use .NET while formatting different number types. Eg .:

Diverse French Cultural Information = CultureInfoGetCalcherInfo ("FR-FR"); Console.WriteLine (frenchCultureInfo.NumberFormat.CurrencySymbol);

It will print to . To rebuild the full format, you have to inspect many properties on the property of NumberFormat . It can be quite difficult as an experiment I have tried to write the necessary code to use the decimal format format specifier:

  var value = -123456.789m; Var culture interval = cultureinfoGetCalcherInfo ("AS-AN"); Var numberform = cultureInfonform; // Create group format like "#, ##, ###". Var Group = NumberAformat .CurrencyGroupSizes. Select (groupSize = & gt; new string ('#', groupSize)); Var format1 = "#," + string .joint (",", group); // Create the number format like "#, ##, ## 0.00" Var format2 = format1.Substring (0, format1.Length - 1) + "0." + New string ('0', number format.currentidualdegit); // Format the number without marking // Note that it is necessary to use the right culture info here. Var formatted number = mathematics. ABS (value) ostring (format 2, culture info); // sign, currency symbol and number combine Var Currency Negative Patterns = New Dictionary & lt; Int32, string & gt; {{0, "{0} {1}"}, {1, "{1} {0}"}, {2, "{0} {1}"}, {3, "{1} {0} "}}; Var Stamp Pattern = New Dictionary & lt; Int32, string & gt; {{0, "({0} {1})"}, {1, "- {0} {1}"}, {2, "{0} - {1}"}, {3, "{0 } {1} - "}, {4," ({1} {0}) "}, {5," - {1} {0} "}, {6," {1} - {0} "} , "{1} {0}", {9, {0} -) "}, {11," {0} {1} - "}, {12," {0} - {1} "}, {13," {1} - {0} "}, {14, "({0} {1})"}, {15, "({1} {0})"}}; Var currency value = value> = Decimal Zorro? Print counterparty [number format.crogrampublished page]: currency negative page [numberFormat.CurrencyNegativePattern]; Var fortified value = string.format (currency correspondence, number format.worksmombol, formatted number); The value of   

formattedValue is ₹ -1, 23,456.79 , which is found when evaluating value.ToString (" C ", cultureinfo) . Obviously, later it is very simple.

Note that some currency symbols include . As a result, you can not always create a custom format string to replace C as or ', which has special meaning in custom numerical format, such as a C format is equal to kr for culture da-dk for positive number #, ## 0.00 kr It will make it impossible to use the form after leaving the dot. Instead, you have to use the approach where the currency symbol is added after the number is marked, or alternatively you can avoid the problematic character.


Comments