changeF2Y static method

String changeF2Y(
  1. int amount, {
  2. MoneyFormat format = MoneyFormat.NORMAL,
})

fen to yuan, format output. 分 转 元, format格式输出.

Implementation

static String changeF2Y(int amount,
    {MoneyFormat format = MoneyFormat.NORMAL}) {
  String moneyTxt;
  double yuan = NumUtil.divide(amount, 100);
  switch (format) {
    case MoneyFormat.NORMAL:
      moneyTxt = yuan.toStringAsFixed(2);
      break;
    case MoneyFormat.END_INTEGER:
      if (amount % 100 == 0) {
        moneyTxt = yuan.toInt().toString();
      } else if (amount % 10 == 0) {
        moneyTxt = yuan.toStringAsFixed(1);
      } else {
        moneyTxt = yuan.toStringAsFixed(2);
      }
      break;
    case MoneyFormat.YUAN_INTEGER:
      moneyTxt = (amount % 100 == 0)
          ? yuan.toInt().toString()
          : yuan.toStringAsFixed(2);
      break;
  }
  return moneyTxt;
}