摘要: JDK1.5中,String类新增了一个很有用的静态方法String.format():format(Locale l, String format, Object... args) 使用指定的语言环境、格式字符串和参数返回一个格式化字符串。format(String format, Object... args) 使用指定的格式字符串和参数返回一个格式化字符串。举几个这个方法实用的例子(注释是输出结果):CODE:long now = System.currentTimeMillis();String s = String.format("%tR", now); // & 阅读全文
posted @ 2013-10-16 17:49 tse johnson 阅读(699) 评论(0) 推荐(0) 编辑
摘要: java保留两位小数问题:方式一:四舍五入double f = 111231.5585;BigDecimal b = new BigDecimal(f);double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();保留两位小数---------------------------------------------------------------方式二:java.text.DecimalFormat df =new java.text.DecimalFormat("#.00");df.format( 阅读全文
posted @ 2013-10-16 17:19 tse johnson 阅读(1802) 评论(0) 推荐(0) 编辑