title: ASP.NET Decimal.Parse()
body: <p>I have problem in webpage , Visual Studio claims that problem is with this line <code>decimal newAmount = PLNamount * Decimal.Parse(item.Value);</code>. The solution is crushed when I choose the Current (web page is simple current converter) .</p>
  <p>this is listing of <strong>CurrencyConverter.aspx.cs</strong></p>
  <pre><code>using System;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;
  public partial class CurrencyConverter : System.Web.UI.Page
  {
      protected void Page_Load(Object sender, EventArgs e)
      {
          if (this.IsPostBack == false)
          {
              // The HtmlSelect control accepts text or ListItem objects.
              Currency.Items.Add(new ListItem(&quot;Euros&quot;, &quot;0.25&quot;));
              Currency.Items.Add(new ListItem(&quot;US Dollar&quot;, &quot;0.32&quot;));
              Currency.Items.Add(new ListItem(&quot;British Pound&quot;, &quot;0.205&quot;));
          }
      }
      protected void Convert_ServerClick(object sender, EventArgs e)
      {
          
          decimal PLNamount;
          
          bool success = Decimal.TryParse(PLN.Value,out PLNamount);
          if (success)
          {
              PLNamount = Decimal.Parse(PLN.Value);
              ListItem item = Currency.Items[Currency.SelectedIndex];
              decimal newAmount = PLNamount * Decimal.Parse(item.Value); //prollematic line
  
              Result.InnerText = PLNamount.ToString() + &quot; Polish PLN = &quot;;
              Result.InnerText += newAmount.ToString() + &quot; &quot; + item.Text;
          }
          else Result.InnerText = &quot;Invalid content&quot;;
      }
  }
  </code></pre>
  <p>This is listing of <strong>CurrencyConverter.aspx</strong></p>
  <pre><code>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;
  CodeFile=&quot;CurrencyConverter.aspx.cs&quot; Inherits=&quot;CurrencyConverter&quot; %&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
  &lt;title&gt;Currency Converter&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Simple Currency Converter in ASP.NET web forms &lt;br /&gt;
  
  &lt;form id=&quot;Form1&quot; runat=&quot;server&quot;&gt;
  &lt;div&gt;
  Convert: &amp;nbsp;
  &lt;input type=&quot;text&quot; ID=&quot;PLN&quot; runat=&quot;server&quot; /&gt;
  &amp;nbsp; Polish PLN to Euros.
  &lt;select ID=&quot;Currency&quot; runat=&quot;server&quot; /&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;OK&quot; ID=&quot;Convert&quot; runat=&quot;server&quot;
  OnServerClick=&quot;Convert_ServerClick&quot; /&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;div style=&quot;font-weight: bold&quot; ID=&quot;Result&quot; runat=&quot;server&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>This Code is changed listing from apress &quot;Pro ASP.NET 3.5 in C# 2008, Second Edition&quot; (original version) from chapter 5. Link to source code apress.com/book/downloadfile/3803 . I have exactly the same problem in the same line</p>
  <p>Original source code from the book</p>
  <p><strong>aspx</strong></p>
  <pre><code>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;
      CodeFile=&quot;CurrencyConverter.aspx.cs&quot; Inherits=&quot;CurrencyConverter&quot; %&gt;
  
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot;
   &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;
  
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
    &lt;head&gt;
      &lt;title&gt;Currency Converter&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form ID=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;&gt;
  
          &lt;div style=&quot;border-right: thin ridge; padding-right: 20px; border-top: thin ridge;
              padding-left: 20px; padding-bottom: 20px; border-left: thin ridge; width: 531px;
              padding-top: 20px; border-bottom: thin ridge; font-family: Verdana; background-color: #FFFFE8&quot;&gt;
          Convert: &amp;nbsp;
          &lt;input type=&quot;text&quot; ID=&quot;US&quot; runat=&quot;server&quot; style=&quot;width: 102px&quot; /&gt;&amp;nbsp; U.S. dollars to &amp;nbsp;
          &lt;select ID=&quot;Currency&quot; runat=&quot;server&quot; /&gt;
          &lt;br /&gt;&lt;br /&gt;
          &lt;input type=&quot;submit&quot; value=&quot;OK&quot; ID=&quot;Convert&quot; runat=&quot;server&quot; OnServerClick=&quot;Convert_ServerClick&quot; /&gt;
          &lt;input type=&quot;submit&quot; value=&quot;Show Graph&quot; ID=&quot;ShowGraph&quot; runat=&quot;server&quot; OnServerClick=&quot;ShowGraph_ServerClick&quot; /&gt;
          &lt;br /&gt;&lt;br /&gt;
          &lt;img ID=&quot;Graph&quot; alt=&quot;Currency Graph&quot; scr=&quot;&quot; runat=&quot;server&quot; /&gt;
          &lt;br /&gt;&lt;br /&gt;
          &lt;div style=&quot;font-weight: bold&quot; ID=&quot;Result&quot; runat=&quot;server&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>aspx.cs</strong></p>
  <pre><code>using System;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;
  
  public partial class CurrencyConverter : System.Web.UI.Page
  {
      protected void Page_Load(Object sender, EventArgs e)
      {
          if (this.IsPostBack == false)
          {
              // The HtmlSelect control accepts text or ListItem objects.
              Currency.Items.Add(new ListItem(&quot;Euros&quot;, &quot;0.85&quot;));
              Currency.Items.Add(new ListItem(&quot;Japanese Yen&quot;, &quot;110.33&quot;));
              Currency.Items.Add(new ListItem(&quot;Canadian Dollars&quot;, &quot;1.2&quot;));
          }
          Graph.Visible = false;
      }
      protected void Convert_ServerClick(object sender, EventArgs e)
      {
          decimal amount;
          bool success = Decimal.TryParse(US.Value, out amount);
          if (success)
          {
              // Retrieve the selected ListItem object by its index number.
              ListItem item = Currency.Items[Currency.SelectedIndex];
  
              decimal newAmount = amount * Decimal.Parse(item.Value);
              Result.InnerText = amount.ToString() + &quot; U.S. dollars = &quot;;
              Result.InnerText += newAmount.ToString() + &quot; &quot; + item.Text;
          }
          else
          {
              Result.InnerText = &quot;The number you typed in was not in the correct format. &quot;;
              Result.InnerText += &quot;Use only numbers.&quot;;
          }
      }
  
      protected void ShowGraph_ServerClick(object sender, EventArgs e)
      {
          Graph.Src = &quot;Pic&quot; + Currency.SelectedIndex.ToString() + &quot;.png&quot;;
          Graph.Visible = true;
      }
  }
  </code></pre>
  <p><strong>Problem solved</strong></p>
  <p>This is link to print screen with this error. <a href="http://img210.imageshack.us/f/currencyerror.png/" rel="nofollow noreferrer">http://img210.imageshack.us/f/currencyerror.png/</a></p>