I have this code, where I do the sum of a column of a jtable, but I have a problem, I want to limit the number of decimals that come out but I did not get it. Try with the DecimalFormat, but I run it and it does not add anything, it comes out as result 0, of a column that does have data. Any suggestions or help?
txtSuma.setText("0");
int ta=jReporteGanadores.getRowCount();
int c=0;
do
try {
int f=c++;
double n1=Double.parseDouble(jReporteGanadores.getValueAt(f,5).toString());
String nu=txtSuma.getText();
double nu2=Double.parseDouble(nu);
double n2=Double.parseDouble(txtSuma.getText());
double re=n1+nu2;//LUGAR A FORMATEAR DECIMALES
String df=String.valueOf(re);
int cd=df.indexOf(".");
String x=df.substring(cd+2);
if(x.isEmpty()){
txtSuma.setText(String.valueOf(re+"0"));
}else{
String vx=txtSuma.getText();
double vx2=Double.parseDouble(vx);
double ref=(double) n1+vx2;
txtSuma.setText(String.valueOf(ref));
}
}catch(Exception e){
}
while(c<ta);