View Single Post
  #2 (permalink)  
Old 11-16-2007, 12:27 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Depends on what you're doing. If you can't get four places because of decimal location or precision issues you can use double. For presentation you can use NumberFormat:
Code:
// see NumberFormat api for options. NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(4); nf.setMaximumFractionDigits(4); String s = nf.format(myFloatValue); // or, in j2se 1.5+ you can specify precision s = String.format("%.4f", yourFloatValue);
DecimalFormat is another class that some use for this.
Reply With Quote