×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Clifton Foster
Added: May 31, 2016 1:55 AM
Modified: May 31, 2016 2:05 AM
Views: 17
Tags: no tags
Convert a string to a double
  1. try {
  2.     Double rateDollarsToPounds = 0.683761; //As of 5/28/2016
  3.     EditText dollarRaw = (EditText) findViewById(R.id.fromCurrency);
  4.     String dollarString = dollarRaw.getText().toString();
  5.     Double dollar = Double.parseDouble(dollarString);
  6.  
  7.     Toast.makeText(getApplicationContext(), dollar + " Dollars = " + (dollar * rateDollarsToPounds) + " Pounds", Toast.LENGTH_LONG).show();
  8.     // dollarString did not contain a valid double
  9. }