need code to Convert rupee to dollar in java
I am writing an appl开发者_JAVA技巧ication java , is any way to write a java code to convert rupee to u.s. dollar and it shoud fetch the current u.s. dollar. I need the program in java
Thanks
Google is our friend. I found this webservice which offers currency conhttp://www.webservicex.net/WS/WSDetails.aspx?WSID=10
You'll either hardcode the exchange rate in your application or database, or you'll be fetching that in real time (or asynchronously & cache every x minutes) from a third party site, for example http://www.google.com/search?q=1+usd+in+inr
In order to do this you would need to fetch the current exchange rate from a web service. The easiest way, if you just need to fetch a page, is something like this:
InputStream is = new URL("http://someexchangesite.com...").openStream();
Then read and parse the InputStream to find the exchange rate, and then use it with some simple multiplication!
Please find the below code which returns json response for getting Conversion Rate.
HttpClient client = new HttpClient();
NameValuePair arg1 = new NameValuePair("method","runJob");
//Change your currency types here in which you would want to convert
NameValuePair arg2 = new NameValuePair("from","USD");
NameValuePair arg3 = new NameValuePair("to", "PKR");
//getting the method
GetMethod method = new GetMethod("http://rate-exchange.appspot.com/currency");
method.setQueryString(new NameValuePair[]{arg1, arg2, arg3});
//executes the link
client.executeMethod(method);
//getting response in string
JSONObject obj = new JSONObject(method.getResponseBodyAsString());
//getting rate from the json response
double rate = obj.getDouble("rate");
//closing conncetion
method.releaseConnection();
//returning value
return rate;
精彩评论