java获取年份的后两位】的更多相关文章

public static String getDate(Date strDate) { String date = null; if (strDate!= null) { Calendar startTime = Calendar.getInstance(); int year = startTime.get(Calendar.YEAR) - 20; // 这里初始化时间,然后设置年份.只以年份为基准,不看时间 startTime.clear(); startTime.set(Calendar…
摘自http://irobot.iteye.com/blog/285537 Java中取小数点后两位(四种方法)   一 Long是长整型,怎么有小数,是double吧     java.text.DecimalFormat   df=new   java.text.DecimalFormat("#.##");     double   d=3.14159;     System.out.println(df.format(d)); 二 java.math.BigDecimal    …
package com.btzh.mis.house.utils; import java.math.BigDecimal;import java.math.RoundingMode;import java.text.DecimalFormat; /** * Double类型数据处理类 * @author weijixiang * @date 2017/10/17. */public class NumberUtil { public static Double saveOneBit(Doubl…
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11.5)的结果为-11. ceil 则是不小于他的最小整数 看例子   Math.floor Math.round Math.ceil 1.4 1 1 2 1.5 1 2 2 1.6 1 2 2 -1.4 -2 -1…
1.方法一 四舍五入: import java.math.BigDecimal; double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 2.方法二 java.text.DecimalFormat df =new java.text.DecimalFormat("#.00"); df.forma…
前言 为了获得一堆apk的大小,并与人类友好方式显示.本来是打算用以下方法,到时不能具体到保留两位小数. org.apache.commons.io.FileUtils.byteCountToDisplaySize(f.length()); Returns a human-readable version of the file size, where the input represents a specific number of bytes. If the size is over 1GB…
已知 双精度标量 f,  如果想以字符串形式输出,小数点后保留2位,可直接通过C语言的输出格式,System.out.printf("%.2f", f), 达到目的. 如果想要先转变成小数点后保留2位的双精度变量,然后再输出,可以尝试用 f 作参数,创建一个 BigDecimal 对象 b,再 调用 BigDeciaml 对象的 setScale 方法,以取得另一个 小数点后2位的新对象,最后,通过这个新对象,调用 方法:doubleValue(),  以取得双精度变量 f1. 最后,…
参考:http://www.jb51.net/article/46010.htm 另,如果只是要在页面层展示的时候,显示为两位小数,也可以直接改前端js代码. item.turnoverRate = parseFloat(item.turnoverRate).toFixed(2); 如果parseFloat发生异常,会显示为NaN.…
package com.taiping.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DataUtil { /** * pattern格式的写法: yyyy:年 MM:月 dd:日 hh:1~12小时制(1-12) HH:24小时制(0-23) mm:分 ss:秒 S:毫秒 E:星期几 D:一年中的第几天 F:一月中的第几个星期(会把这…
  1.(double) (Math.round(sd3*10000)/10000.0);  这样为保持4位 (double) (Math.round(sd3*100)/100.0); 这样为保持2位. 2.另一种办法 import java.text.DecimalFormat; DecimalFormat df2  = new DecimalFormat("###.00"); DecimalFormat df2  = new DecimalFormat("###.000&…