Hey there are different way to format number. I had written 3 example to do this. Just go through it.
Code:
double p = 2.6854;
System.out.println(p); // p is 2.6854
int q = 3;
BigDecimal d = new BigDecimal(p);
// setScale is immutable
d = d.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
p = d.doubleValue();
System.out.println(p); // p is 2.68
Code:
d = (float) (Math.round(n*1200.0f)/200.0f);
Code:
DecimalFormat cms = new DecimalFormat( "#,###,###,##0.00" );
double fg = 100.2397;
double fg2erd = new Double(dfg.format(dfg)).doubleValue();
// The value of fg2erddec will be 200.23
Bookmarks