/** * 元轉分,確保price保留兩位有效數字 * @return */ public static int changeY2F(double price) { DecimalFormat df = new DecimalFormat("#.00"); price = Double.valueOf(df.format(price)); int money = (int)(price * 100); return money; } /** * 分轉元,轉換為bigDecimal在toString * @return */ public static String changeF2Y(int price) { return BigDecimal.valueOf(Long.valueOf(price)).divide(new BigDecimal(100)).toString(); }
