123456789101112131415161718192021222324252627282930 |
- package cn.efunbox.base.util;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- /**
- * MoneyUtil
- * Created by xusq on 2020/1/6.
- */
- public class MoneyUtil {
- /**
- * 元转分,确保price保留两位有效数字
- * @return
- */
- public static long changeY2F(double price) {
- DecimalFormat df = new DecimalFormat("#.00");
- price = Double.valueOf(df.format(price));
- long money = (long)price * 100;
- return money;
- }
- /**
- * 分转元,转换为bigDecimal在toString
- * @return
- */
- public static String changeF2Y(long price) {
- return BigDecimal.valueOf(price).divide(new BigDecimal(100)).toString();
- }
- }
|