java 枚举 静态_Java 静态内部类和枚举(银联支付)

//这里面主要是由于银联的手机支付用到了一个付款的转换方式问题,当调用支付宝付款的时候,比如一分钱格式就是我们普通用的格式:0.01,而银联确要把格式转化为000000000001(银联要求是12位)这种格式的,最后一位是分,然后向前依次是角,元,十元,百元,相信不用我说,你已经懂了吧。所以这里就需要一个转换,为了应对像1000,1000.00,1000.0这种传过来的格式的数据,特做一下转换,然后传给银联进行支付。

package com.abin.lee.collection.inner;

public class ConsumeFinance {

public static enum Currency{

CHINARMB("chinarmb"),DOLLAR("dollar"),HK("hk");

private Currency(String textVal){

this.textVal=textVal;

}

private String textVal;

public String toString(){

return textVal;

}

}

public static String ConsumeProcess(String money,Currency currency){

System.out.println("currentcy="+currency);

String flag=null;

if(currency.equals(Currency.CHINARMB)){

ConsumeFinance.ChinaProcess chinaProcess=new ConsumeFinance.ChinaProcess();

flag=chinaProcess.chinaChange(money, currency);

}

return flag;

}

public static String ConsumeProcessReturn(String money,Currency currency){

System.out.println("currentcy="+currency);

String flag=null;

if(currency.equals(Currency.CHINARMB)){

ConsumeFinance.ChinaReturn chinaReturn=new ConsumeFinance.ChinaReturn();

flag=chinaReturn.chinaReChange(money, currency);

}

return flag;

}

public static class ChinaProcess{

private static String status=null;

public static String chinaChange(String money,Currency currency){

int point=money.lastIndexOf(".");

if(point==-1){

StringBuffer stb=new StringBuffer();

int len=money.length();

int lon=10-len;

for(int i=0;i

stb.append("0");

}

stb.append(money);

stb.append("00");

status=stb.toString().intern();

}

if(point>0){

int len=money.indexOf(".");

int chn=money.length()-len-1;

switch(chn){

//先判断money格式为100.0这种格式的,小数点后面有一位小数点的情况

case  1:

StringBuffer stb=new StringBuffer(money);

stb.deleteCharAt(len);

int lend=stb.length();

StringBuffer sb=new StringBuffer();

for(int i=0;i<12-lend;i++){

sb.append("0");

}

sb.append(stb.toString());

status=sb.toString().intern();

//先判断money格式为100.01这种格式的,小数点后面有两位小数点的情况

case 2:

money=money.replace(".", "");

int lende=money.length();

String connect="";

for(int i=0;i<12-lende;i++){

connect+="0";

}

status=connect+money;

}

}

return status;

}

}

//把000000001001转化为10.01这种格式

public static class ChinaReturn{

private static String status=null;

public static String chinaReChange(String money,Currency currency){

int change=money.length();

int num=0;

for(int i=0;i

int value=Integer.valueOf(String.valueOf(money.charAt(i)));

if(value>0){

num=i;

break;

}

}

money=money.substring(num);

if(num==10){

status="0."+money;

}

if(num==11){

status="0.0"+money;

}

if(num<10){

System.out.println(money.length());

StringBuffer stb=new StringBuffer(money);

stb.insert(money.length()-2, ".");

status=stb.toString().intern();

}

return status;

}

}

public static void main(String[] args) {

Currency currency=Currency.CHINARMB;

String money="000000001001";

String result=ConsumeProcessReturn(money, currency);

//String result=ConsumeProcess(money, currency);

System.out.println("result="+result);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值