0

I want to print 6.5 to 6.05. And 6.12 to 6.12.

How it could be achieved using java utilities?

I tried DecimalFormat as below:

DecimalFormat df = new DecimalFormat("##.0#");
System.out.println("sam --------- " + df.format(6.5));

But not working. Any help on this?

mnille
  • 1,328
  • 4
  • 16
  • 20
Abhendra Singh
  • 1,959
  • 4
  • 26
  • 46
  • ``6.5`` to ``6.05`` is not just a printing problem: it is a conversion problem. What are the rules? – Jean Logeart Apr 27 '16 at 19:16
  • you can do like this : double a = 6.5; String as = Double.toString(a); if(as.length() == 3) { as = as.substring(0, 1) + ".0" + as.substring(2, as.length()); System.out.println(as); } – V. Sambor Apr 27 '16 at 19:30

0 Answers0