code_junkie

java decimal String format

Nov 13th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. "34.49596" would be "34.4959"
  2. "49.3" would be "49.30"
  3.  
  4. DecimalFormat df = new DecimalFormat("0.00##");
  5. String result = df.format(34.4959);
  6.  
  7. double a = 34.51234;
  8.  
  9. NumberFormat df = DecimalFormat.getInstance();
  10. df.setMinimumFractionDigits(2);
  11. df.setMaximumFractionDigits(4);
  12. df.setRoundingMode(RoundingMode.DOWN);
  13.  
  14. System.out.println(df.format(a));
Add Comment
Please, Sign In to add comment