title: ASP.NET MVC binding decimal value
body: <p>I'm trying to figure out why framework refuses to bind "1,234.00" value to decimal. What can be the reason for it?</p>
  
  <p>Values like "123.00" or "123.0000" bind successfully.</p>
  
  <p>I have the following code setting my culture config in Global.asax</p>
  
  <pre><code>    public void Application_AcquireRequestState(object sender, EventArgs e)
      {
          var culture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
          culture.NumberFormat.NumberDecimalSeparator = culture.NumberFormat.CurrencyDecimalSeparator = culture.NumberFormat.PercentDecimalSeparator = ".";
          culture.NumberFormat.NumberGroupSeparator = culture.NumberFormat.CurrencyGroupSeparator = culture.NumberFormat.PercentGroupSeparator = ",";
          Thread.CurrentThread.CurrentCulture = culture;
      }
  </code></pre>
  
  <p>French culture is set as default culture in Web.Config</p>
  
  <pre><code>  &lt;globalization uiCulture="fr-FR" culture="fr-FR" /&gt;
  </code></pre>
  
  <p>I've dived into sources of System.Web.Mvc.dll's ValueProviderResult class. It is using System.ComponentModel.DecimalConverter. </p>
  
  <pre><code>converter.ConvertFrom((ITypeDescriptorContext) null, culture, value)
  </code></pre>
  
  <p>Here is where the message "1,234.0000 is not a valid value for Decimal." comes from.</p>
  
  <p>I've tried to run the following code in my playground:</p>
  
  <pre><code>static void Main()
  {
      var decConverter = TypeDescriptor.GetConverter(typeof(decimal));
      var culture = new CultureInfo("fr-FR");
      culture.NumberFormat.NumberDecimalSeparator = culture.NumberFormat.CurrencyDecimalSeparator = culture.NumberFormat.PercentDecimalSeparator = ".";
      culture.NumberFormat.NumberGroupSeparator = culture.NumberFormat.CurrencyGroupSeparator = culture.NumberFormat.PercentGroupSeparator = ",";
      Thread.CurrentThread.CurrentCulture = culture;
      var d1 = Decimal.Parse("1,232.000");
      Console.Write("{0}", d1);  // prints  1234.000     
      var d2 = decConverter.ConvertFrom((ITypeDescriptorContext)null, culture, "1,232.000"); // throws "1,234.0000 is not a valid value for Decimal."
      Console.Write("{0}", d2);
  }
  </code></pre>
  
  <p>DecimalConverter throws same exception. Decimal.Parse correctly parses the same string.</p>