java - Round Double value in Swing -
i have mentioned code given below.my question @ data.setvalueat(28.7567, 1, 1); value should displayed 28.757 taking 28.7567000000000 jtable.class adding zero's or other class there consider value double , how resove problem?
import java.awt.color; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jscrollpane; import javax.swing.jtable; import util.leveleditor.components.letablemodel; public class jrtest { public static void main(string args[]) { object[][] datal = new object[30][30]; object[] titles = new object[30]; letablemodel model = new letablemodel(datal, titles); jtable data = new jtable(model); data.setfillsviewportheight(true); data.setautoresizemode(jtable.auto_resize_off); data.setshowgrid(true); data.setgridcolor(color.black); data.settableheader(null); jframe frame = new jframe("test"); frame.add(new jscrollpane(data)); data.setvalueat(28.7567, 1, 1); frame.pack(); frame.setvisible(true); } }
the first parameter of jtable.setvalueat()
method object type. so, if want 28.757 pass directly string.
data.setvalueat("28.757", 1, 1);
or if want pass double value , if want should formatted 3 decimals, use formatter.
check following link: best way format double value 2 decimal places
Comments
Post a Comment