0

How can I input a decimal or double number as it is? I want if I input .56 it saves in the database as .56 not 1 because its rounding up and I want to ignore the rounding...

This is servlet, well I have beans and its also set to double; I also tried DecimalFormat but still not working or maybe I just don't know how to use it.

neutrophils = rs.getInt("neutrophils");
monocytes = rs.getInt("monocytes");
eosinophils = rs.getInt("eosinophils");
basophils = rs.getInt("basophils");
lymphocytes = rs.getInt("lymphocytes");

total= (neutrophils + monocytes + eosinophils + eosinophils + basophils + lymphocytes);

I made it like this, I changed the value of datatype to VARCHAR but the error is java.lang.NullPointerException; why is that?

neutrophils = Double.parseDouble(rs.getString("neutrophils"));
monocytes = Double.parseDouble(rs.getString("monocytes"));
eosinophils = Double.parseDouble(rs.getString("eosinophils"));
basophils = Double.parseDouble(rs.getString("basophils"));
lymphocytes = Double.parseDouble(rs.getString("lymphocytes"));
bands = (neutrophils + monocytes + eosinophils + eosinophils + basophils + lymphocytes); 
4

1 回答 1

0

If rs is ResultSet you can simply use rs.getDouble. If for some reason you don't want to use it, get the result as a String and then convert

Double.parseDouble(rs.getString(ColumnLabel));
于 2013-10-26T04:01:57.367 回答