人民币转换

public class TranMoney {
 public TranMoney() {
 }
// public static void main(String ars[]){
//  System.out.println(getChnmoney("11000.01"));
//  
// }
 public static String getChnmoney(String strNum) {
  int n, m, k, i, j, q, p, s = 0;
  int length, subLength, pstn;
  String change, output, subInput, input = strNum;
  output = "";
  if (strNum.equals(""))
   return null;
  else {
   length = input.length();
   pstn = input.indexOf('.'); // 小数点的位置

   if (pstn == -1) {
    subLength = length;// 获得小数点前的数字
    subInput = input;
   } else {
    subLength = pstn;
    subInput = input.substring(0, subLength);
   }

   char[] array = new char[4];
   char[] array2 = { '仟', '佰', '拾' };
   char[] array3 = { '亿', '万', '元', '角', '分' };

   n = subLength / 4;// 以千为单位
   m = subLength % 4;

   if (m != 0) {
    for (i = 0; i < (4 - m); i++) {
     subInput = '0' + subInput;// 补充首位的零以便处理
    }
    n = n + 1;
   }
   k = n;

   for (i = 0; i < n; i++) {
    p = 0;
    change = subInput.substring(4 * i, 4 * (i + 1));
    array = change.toCharArray();// 转换成数组处理

    for (j = 0; j < 4; j++) {
     output += formatC(array[j]);// 转换成中文
     if (j < 3) {
      output += array2[j];// 补进单位,当为零是不补(千百十)
     }
     p++;
    }

    if (p != 0)
     output += array3[3 - k];// 补进进制(亿万元分角)
    // 把多余的零去掉

    String[] str = { "零仟", "零佰", "零拾" };
    for (s = 0; s < 3; s++) {
     while (true) {
      q = output.indexOf(str[s]);
      if (q != -1)
       output = output.substring(0, q) + "零"
         + output.substring(q + str[s].length());
      else
       break;
     }
    }
    while (true) {
     q = output.indexOf("零零");
     if (q != -1)
      output = output.substring(0, q) + "零"
        + output.substring(q + 2);
     else
      break;
    }
    String[] str1 = { "零亿", "零万", "零元" };
    for (s = 0; s < 3; s++) {
     while (true) {
      q = output.indexOf(str1[s]);
      if (q != -1)
       output = output.substring(0, q)
         + output.substring(q + 1);
      else
       break;
     }
    }
    k--;
   }

   if (pstn != -1)// 小数部分处理
   {
    for (i = 1; i < length - pstn; i++) {
     if (input.charAt(pstn + i) != '0') {
      output += formatC(input.charAt(pstn + i));
      output += array3[2 + i];
     } else if (i < 2)
      output += "零";
     else
      output += "";
    }
   }
   if (output.substring(0, 1).equals("零"))
    output = output.substring(1);
   if (output.substring(output.length() - 1, output.length()).equals(
     "零"))
    output = output.substring(0, output.length() - 1);
   if(output.indexOf("分")>0||output.indexOf("角")>0){
    return output;
   }else{
    return output += "整";
   }
   
  }
 }

 public static String get3Eng(String strNum) {
  String strEng = "";
  String str[] = { "", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
    "SEVEN", "EIGHT", "NINE" };
  String str1[] = { "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN",
    "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" };
  String str2[] = { "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY",
    "SEVENTY", "EIGHTY", "NINETY", "HUNDRED" };
  int num = Integer.parseInt(strNum);
  int b = num / 100;
  int t = (num % 100) / 10;
  int g = (num % 100) % 10;
  if (b != 0) {
   strEng = strEng + str[b] + " " + str2[9];
  }

  if (t == 0) {
   if (g != 0) {
    if (b != 0) {
     strEng = strEng + " AND ";
    }
    strEng = strEng + str[g];
   }
  } else if (t == 1) {
   if (b != 0) {
    strEng = strEng + " AND ";
    num = num % 100;
   }
   strEng = strEng + str1[num - 10];
  } else if (t != 1) {
   if (g != 0) {
    if (b != 0) {
     strEng = strEng + " AND ";
    }
    strEng = strEng + str2[t - 1] + "-" + str[g];
   } else {
    if (b != 0) {
     strEng = strEng + " AND ";
    }
    strEng = strEng + str2[t - 1] + str[g];
   }
  }
  return strEng;
 }

 public static String getCent(String strNum) {
  String strEng = "";
  String str[] = { "", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
    "SEVEN", "EIGHT", "NINE" };
  String str1[] = { "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN",
    "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" };
  String str2[] = { "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY",
    "SEVENTY", "EIGHTY", "NINETY", "HUNDRED" };
  String str3[] = { "CENTS", "", "DOLLARS", "", "HUNDRED", "THOUSAND",
    "", "", "MILLION", "", "", "BILLION", "", "" };
  if (strNum.equals(""))
   return null;
  else {
   int length = strNum.length();
   if (length != 3) {
    return "输入的位数错误!";
   }
   int cent = Integer.parseInt(strNum.substring(1, 3));
   if (cent == 0) {
    return strEng;
   }
   if (cent < 10) {
    strEng = str3[0] + " " + strEng + str[cent];
   } else if (cent >= 10 && cent <= 19) {
    strEng = str3[0] + " " + strEng + str1[cent - 10];
   } else if (cent > 19) {
    int jiao = cent / 10;
    int fen = cent % 10;
    if (fen != 0) {
     strEng = str3[0] + " " + strEng + str2[jiao - 1] + "-"
       + str[fen];
    } else {
     strEng = str3[0] + " " + strEng + str2[jiao - 1] + str[fen];
    }
   }
   return strEng;
  }
 }

 public static String getEngmoney(String strNum) {
  String strNumber = "";
  String str3[] = { "CENTS", "", "DOLLARS", "", "HUNDRED", "THOUSAND",
    "", "", "MILLION", "", "", "BILLION", "", "" };
  String strEng = "";
  strNumber = strNum;
  int pointbz = strNumber.indexOf(".");
  if (pointbz < 0) {
   strNumber = strNumber + ".00";
  } else if (pointbz > 0) {
   int k = strNum.length() - pointbz;
   if (k == 2) {
    strNumber = strNumber + "0";
   } else if (k == 1) {
    strNumber = strNumber + "00";
   }
  }
  int length = strNumber.length();
  if (length > 16) {
   return "您输入的值过大系统无法处理!";
  }
  String strb = "";
  String strm = "";
  String strq = "";
  String stry = "";
  String strf = "";
  // 得到分
  if (length == 3) {
   strf = getCent(strNumber);
   strEng = strEng + strf;
  } else if (length > 3 && length < 7) {
   stry = get3Eng(strNumber.substring(0, length - 3));
   strf = getCent(strNumber.substring(length - 3, length));
   strEng = strEng + stry + " " + str3[2];
   if (!strf.equals("")) {
    strEng = strEng + " AND " + strf;
   }
  } else if (length > 6 && length < 10) {
   strq = get3Eng(strNumber.substring(0, length - 6));
   stry = get3Eng(strNumber.substring(length - 6, length - 3));
   strf = getCent(strNumber.substring(length - 3, length));
   strEng = strEng + strq + " " + str3[5];
   if (stry.equals("")) {
    strEng = strEng + " " + stry;
   } else {
    strEng = strEng + " " + stry + " " + str3[2];
   }
   if (!strf.equals("")) {
    strEng = strEng + " AND " + strf;
   }
  } else if (length > 9 && length < 13) {
   strm = get3Eng(strNumber.substring(0, length - 9));
   strq = get3Eng(strNumber.substring(length - 9, length - 6));
   stry = get3Eng(strNumber.substring(length - 6, length - 3));
   strf = getCent(strNumber.substring(length - 3, length));
   strEng = strEng + strm + " " + str3[8];
   if (!strq.equals("")) {
    strEng = strEng + " " + strq + " " + str3[5];
   }
   if (!stry.equals("")) {
    strEng = strEng + " " + stry + " " + str3[2];
   } else {
    strEng = strEng + " " + str3[2];
   }
   if (!strf.equals("")) {
    strEng = strEng + " AND " + strf;
   }
  } else if (length > 12 && length < 16) {
   strb = get3Eng(strNumber.substring(0, length - 12));
   strm = get3Eng(strNumber.substring(length - 12, length - 9));
   strq = get3Eng(strNumber.substring(length - 9, length - 6));
   stry = get3Eng(strNumber.substring(length - 6, length - 3));
   strf = getCent(strNumber.substring(length - 3, length));
   strEng = strEng + strb + " " + str3[11];
   if (!strm.equals("")) {
    strEng = strEng + " " + strm + " " + str3[8];
   }
   if (!strq.equals("")) {
    strEng = strEng + " " + strq + " " + str3[5];
   }
   if (!stry.equals("")) {
    strEng = strEng + " " + stry + " " + str3[2];
   } else {
    strEng = strEng + " " + str3[2];
   }
   if (!strf.equals("")) {
    strEng = strEng + " AND " + strf;
   }
  }

  return strEng + " ONLY";
 }

 public static String formatC(char x) {
  String a = "";
  switch (x) {
  case '0':
   a = "零";
   break;
  case '1':
   a = "壹";
   break;
  case '2':
   a = "贰";
   break;
  case '3':
   a = "叁";
   break;
  case '4':
   a = "肆";
   break;
  case '5':
   a = "伍";
   break;
  case '6':
   a = "陆";
   break;
  case '7':
   a = "柒";
   break;
  case '8':
   a = "捌";
   break;
  case '9':
   a = "玖";
   break;
  }
  return a;
 }
}

内容概要:本文深入探讨了Kotlin语言在函数式编程和跨平台开发方面的特性和优势,结合详细的代码案例,展示了Kotlin的核心技巧和应用场景。文章首先介绍了高阶函数和Lambda表达式的使用,解释了它们如何简化集合操作和回调函数处理。接着,详细讲解了Kotlin Multiplatform(KMP)的实现方式,包括共享模块的创建和平台特定模块的配置,展示了如何通过共享业务逻辑代码提高开发效率。最后,文章总结了Kotlin在Android开发、跨平台移动开发、后端开发和Web开发中的应用场景,并展望了其未来发展趋势,指出Kotlin将继续在函数式编程和跨平台开发领域不断完善和发展。; 适合人群:对函数式编程和跨平台开发感兴趣的开发者,尤其是有一定编程基础的Kotlin初学者和中级开发者。; 使用场景及目标:①理解Kotlin中高阶函数和Lambda表达式的使用方法及其在实际开发中的应用场景;②掌握Kotlin Multiplatform的实现方式,能够在多个平台上共享业务逻辑代码,提高开发效率;③了解Kotlin在不同开发领域的应用场景,为选择合适的技术栈提供参考。; 其他说明:本文不仅提供了理论知识,还结合了大量代码案例,帮助读者更好地理解和实践Kotlin的函数式编程特性和跨平台开发能力。建议读者在学习过程中动手实践代码案例,以加深理解和掌握。
内容概要:本文深入探讨了利用历史速度命令(HVC)增强仿射编队机动控制性能的方法。论文提出了HVC在仿射编队控制中的潜在价值,通过全面评估HVC对系统的影响,提出了易于测试的稳定性条件,并给出了延迟参数与跟踪误差关系的显式不等式。研究为两轮差动机器人(TWDRs)群提供了系统的协调编队机动控制方案,并通过9台TWDRs的仿真和实验验证了稳定性和综合性能改进。此外,文中还提供了详细的Python代码实现,涵盖仿射编队控制类、HVC增强、稳定性条件检查以及仿真实验。代码不仅实现了论文的核心思想,还扩展了邻居历史信息利用、动态拓扑优化和自适应控制等性能提升策略,更全面地反映了群体智能协作和性能优化思想。 适用人群:具备一定编程基础,对群体智能、机器人编队控制、时滞系统稳定性分析感兴趣的科研人员和工程师。 使用场景及目标:①理解HVC在仿射编队控制中的应用及其对系统性能的提升;②掌握仿射编队控制的具体实现方法,包括控制器设计、稳定性分析和仿真实验;③学习如何通过引入历史信息(如HVC)来优化群体智能系统的性能;④探索中性型时滞系统的稳定性条件及其在实际系统中的应用。 其他说明:此资源不仅提供了理论分析,还包括完整的Python代码实现,帮助读者从理论到实践全面掌握仿射编队控制技术。代码结构清晰,涵盖了从初始化配置、控制律设计到性能评估的各个环节,并提供了丰富的可视化工具,便于理解和分析系统性能。通过阅读和实践,读者可以深入了解HVC增强仿射编队控制的工作原理及其实际应用效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值