Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to include the culture when formatting for your strings. You can either use <a href="http://msdn.microsoft.com/en-us/library/1ksz8yb7" rel="nofollow noreferrer">String.Format</a> and include the culture as the first parameter or use the object's <a href="http://msdn.microsoft.com/en-us/library/18sthszb.aspx" rel="nofollow noreferrer">ToString</a> method and use the overload that takes a culture.</p> <p>The following code produces the expected output (except for gws-FR, it couldn't find a culture with that string).</p> <pre><code>namespace CultureFormatting { using System; using System.Globalization; class Program { public static void Main() { Decimal value = -1234567890.1234789012M; Print("en-US", value); Print("ca-ES", value); //print("gws-FR", value); Print("fr-CH", value); Print("ar-DZ", value); Print("prs-AF", value); Print("ps-AF", value); Print("as-IN", value); Print("lo-LA", value); Print("qps-PLOC", value); } static void Print(string cultureName, Decimal value) { CultureInfo cultureInfo = new CultureInfo(cultureName); cultureInfo.NumberFormat.NumberDecimalDigits = 10; // Or, you could replace the {1:N} with {1:N10} to do the same // for just this string format call. string result = String.Format(cultureInfo, "{0,-8} {1:N}", cultureName, value); Console.WriteLine(result); } } } </code></pre> <p>The above code produces the following output:</p> <pre><code>en-US -1,234,567,890.1234789012 ca-ES -1.234.567.890,1234789012 fr-CH -1'234'567'890.1234789012 ar-DZ 1,234,567,890.1234789012- prs-AF 1.234.567.890,1234789012- ps-AF 1،234،567،890,1234789012- as-IN -1,23,45,67,890.1234789012 lo-LA (1234567,890.1234789012) qps-PLOC --12,,3456,,7890..1234789012 </code></pre> <p>If you're working with a multithreaded system, such as ASP.Net, you can change the thread's <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx" rel="nofollow noreferrer">CurrentCulture</a> property. Changing the thread's culture will allow all of the associated <code>ToString</code> and <code>String.Format</code> calls to use that culture.</p> <h3>Update</h3> <p>Since you're wanting to display all of the precision you're going to have to do a bit of work. Using <code>NumberFormat.NumberDecimalDigits</code> will work, except that if the value has less precision, the number will output with trailing zeros. If you need to make sure you display every digit without any extras, you will need to calculate the precision beforehand and set that before you convert it to a string. The StackOverflow question <a href="https://stackoverflow.com/questions/763942/calculate-system-decimal-precision-and-scale">Calculate System.Decimal Precision and Scale</a> may be able to help you determine the precision of the decimal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload