I have table in Microsoft Sql server database and it is having columns of float datatype. I am trying to retrieve the values of these column type in Java ResultSet and then using those values. Below is code for the same.
while (rsTran.next()) {
txnList.add(rsTran.getInt(1));
for (int i = 4; i <= col; i++) {
if (i != col) {
if (i == 9 || i == 10) {
System.out.println("BigDecimal Value:" + rsTran.getBigDecimal(i));
System.out.println("Float Value:" + rsTran.getDouble(i));
tranFileWriter.append(rsTran.getBigDecimal(i) != null ? (rsTran.getBigDecimal(i)+"") : "");
} else {
tranFileWriter.append(rsTran.getString(i) != null ? rsTran.getString(i) : "");
}
tranFileWriter.append('|');
} else if (i == col) {
tranFileWriter.append("MT" + rsTran.getString(i));
}
}
tranFileWriter.append(NEW_LINE_SEPARATOR);
}
It is behaving weird when the values for those float data type column is ending with zero. The sysout statements are printing value in exponential format when values is ending with zero and it is printing fine when value is not ending with zero. for example the value 1986373620.00, 1986373620 will be printed as below.
BigDecimal Value:1.98637362E+9
And if the value is 1986373622 then it prints the exact value and which is fine.
BigDecimal Value:1986373622
Any thoughts why it behaving like this only for the values ending with zeros.