Date Conversion:
public Date stringToDate(String dateString) throws ParseException {
if (dateString.trim() == null || "".equalsIgnoreCase(dateString.trim())) {
return null;
} else {
java.util.Date date = null;
date = new SimpleDateFormat("MM/DD/yyyy", Locale.ENGLISH)
.parse(dateString);
return new Date(date.getTime());
}
}
String to Float Conversion :
public float stringToFloat(String value) throws ParseException {
String sValue = value.trim();
sValue = sValue.replaceAll(",", "");
float returnValue = 0;
if (sValue == null || "".equalsIgnoreCase(sValue)) {
return returnValue;
} else {
returnValue = Float.parseFloat(sValue);
return returnValue;
}
}
String to Double Conversion:
public double stringToDouble(String value) throws ParseException {
String sValue = value.trim();
sValue = sValue.replaceAll(",", "");
double returnValue = 0;
if (sValue == null || "".equalsIgnoreCase(sValue)) {
return returnValue;
} else {
returnValue = Double.parseDouble(sValue);
return returnValue;
}
}
No comments:
Post a Comment