Java tutorial
//package com.java2s; import android.util.Log; public class Main { private static final String TAG = "WareNinjaUtils"; private static Long mMaxLong = Long.valueOf(Long.MAX_VALUE); public static Long stringToLong(String str) { if (str == null) { return null; } else { try { return Long.parseLong(str); } catch (NumberFormatException e) { try { Double d = Double.valueOf(str); if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) { Log.w(TAG, "Value " + d + " too large for long"); return null; } return Long.valueOf(d.longValue()); } catch (NumberFormatException nfe2) { Log.w(TAG, "Unable to interpret value " + str + " in field being " + "converted to long, caught NumberFormatException <" + nfe2.getMessage() + "> field discarded"); return null; } } } } }