/** * 分转元 * 示例 * 100 =>1.00 * 0 =>0.00 * 3 =>0.03 * * @param price * @return */ public static String fen2yuan(int price) { // 创建一个百分比化对象 NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.CHINA); // 设置精确到小数点后2位 numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); String format = numberFormat.format(BigDecimal.valueOf(price).divide(BigDecimal.valueOf(100))); return format.replace("¥", ""); } /** * 元转分 * 示例 * 100 => 10000 * 0=>0 * 0.1=>10 * * @param price * @return */ public static int yuan2fen(double price) { DecimalFormat df = new DecimalFormat("#.00"); price = Double.valueOf(df.format(price)); int money = (int) (price * 100); return money; }