DecimalFormat df = new DecimalFormat( "0.## "); Float si=mfile.getSize()/1024f/1024f; System.out.println(df.format(si)+"M");