currencyConverter C# ERROR

Posted by Diluka under C# on 7/5/2012 | Points: 10 | Views : 946 | Status : [Member] | Replies : 6
private void btnConverter_Click(object sender, RoutedEventArgs e)
{
double CurrencyAmount;
//Check for a numeric value entered into the Amount textbox
try
{
CurrencyAmount = double.Parse(TxtAmount.Text);
}
catch
{
LblResult.Text = "Please enter a Numeric Value!";

return;
}

try
{
string Result = null;
string url;

//Call the web service to get the exchange rate for the two currencies selected by the user
url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=" + cmbDdlFromCurrency.SelectedValue + "&ToCurrency=" + cmbDdlToCurrency.SelectedValue + "";



HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader Stream = new StreamReader(response.GetResponseStream());
XmlDocument doc = new XmlDocument();
Result = Stream.ReadToEnd();
doc.LoadXml(Result);

//Retrieve the conversion rate
string NewConversionRate = doc.GetElementsByTagName("double").Item(0).InnerText;
////Convert the conversion rate string to a double
double ConversionRate = double.Parse(NewConversionRate);

//Calculate the currency exchange
double ConvertedAmount = CurrencyAmount * ConversionRate;
////Display the results on the Default.aspx page
LblResult.Text = Convert.ToString(ConvertedAmount);

//TxtAmount.Text + " " + cmbDdlFromCurrency.SelectedItem + " = " + dblConverted + " " + cmbDdlToCurrency.SelectedItem;
}
catch
{
LblResult.Text = "Oops..Web Service Not available. Try again later";
}

}

i tried to created the currency converter use in webservice but it doesn't work every time i executed the programmer its display Oops error please anyone can tell me what is the error and what i want to do ???? and i created this code for wpf application ..please help to solve this problem :)




Responses

Posted by: Premalatha on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Try this;

String.Format( "{ 0:C}", yourvalue );

It will convert 1234567.0000 to 1,234,567.00 format.

Premalatha
Software Engineer

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
And you can use this also
from decimal to currency
string.Format("{0:C}",decimalvalue )

Premalatha
Software Engineer

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
string.Format("{0:C}",decimalvalue )

or Try this;

String.Format( "{ 0:C}", yourvalue );

It will convert 1234567.0000 to 1,234,567.00 format.

Premalatha
Software Engineer

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Diluka on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
thanks for your suggestions but actually i want to convert one currency into another currency(eg- rupees to dollars )

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&WSID=10

Premalatha
Software Engineer

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Diluka on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
thanks i will try :))

Diluka, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response