实现数字向人民币大写转换

最近,在一个银行项目中接触到把数字向人民币大写转换的问题。其实也并不难,我们需要一个方法把数字分割成个位,十位,百位等进行替换。

下面是一个实现两位数的数字向人民币大写方式的转换案例:

 public Object execute(Object[] args) throws Exception {
    	  int amout = ((Integer)args[0]).intValue();
    	    String[] str = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };

    	    String result = "";
    	    if (amout <= 10) {
    	      result = str[(amout - 1)] + "元";
    	    } else {
    	      int ten = amout / 10;
    	      int gewei = amout % 10;

    	      String shiWei = "";
    	      if (ten == 1)
    	        shiWei = "拾";
    	      else {
    	        shiWei = str[(ten - 1)] + "拾";
    	      }
    	      if (gewei == 0)
    	        result = shiWei + "元";
    	      else {
    	        result = shiWei + str[(gewei - 1)] + "元";
    	      }
    	    }

    	    System.out.println(result);
    	    return result;
    }
在main方法中,进行调用
 public static void main(String[] args) throws Exception {
    	Question1 a = new Question1();
    	  a.execute(new Object[] { Integer.valueOf(4) });
    	    a.execute(new Object[] { Integer.valueOf(10) });
    	    a.execute(new Object[] { Integer.valueOf(11) });
    	    a.execute(new Object[] { Integer.valueOf(25) });
    	    a.execute(new Object[] { Integer.valueOf(89) });
    	    a.execute(new Object[] { Integer.valueOf(90) });
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值