Showing posts with label Basics. Show all posts
Showing posts with label Basics. Show all posts

Thursday, January 5, 2012

Android String to long

Android from String to long

String sNum = "99999999";
long lNum = 0;
try {
   lNum = Long.parseLong(sNum);
} catch(NumberFormatException nfe) {
   Log.e("TAG", "Could not parse " + nfe);
}

Android String to double

Android from String to double

       String sNum = "9.9";
       double dNum = 0;
       try {
              dNum = Double.parseDouble(sNum);
       } catch(NumberFormatException nfe) {
          Log.e("TAG", "Could not parse " + nfe);
       }

                    

Android String to float

Android from String to float  
       String sNum = "9.9";
       float fNum = 0;
       try {
              fNum = Float.parseFloat(sNum);
       } catch(NumberFormatException nfe) {
          Log.e("TAG", "Could not parse " + nfe);
       }

Android String to int

Android from String to int

 
              String sNum = "9";
              int iNum = 0;
              try {
                            iNum = Integer.parseInt(sNum);
              } catch(NumberFormatException nfe) {
                 Log.e("TAG", "Could not parse " + nfe);
              }