介绍
这篇文章主要介绍了使用java怎么将数字转换为中文大写的人民币,此处通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考价值,需要的朋友可以参考下:
java代码
public class Data2Zh { ,final static  private String 数字[],=,{,“零”,,“壹”,,“贰”,,“叁”,,“肆”,,“伍”,,“陆”,,“柒”,,“捌,,,“玖”,}; ,final static  private String 科学[],=,{,“〇”,,“一”,,“二”,,“三”,,“四”,,“五”,,“六”,,“七”,,“八”,,“九”,}; ,final static  private String  CBit[],=,{,,,,,“拾”,,“佰“,,“仟“,};/* * ,*将数值大写 ,*/,public static  String 资本化(String szNum), { ,StringBuilder resstr =, new StringBuilder (); ,String tmpstr =, szNum.trim (); ,int sl =, tmpstr.length (); ,int sp =, 0; ,int dotpos =, tmpstr.indexOf(& # 39; # 39;公司); ,if (dotpos !=, 1), { ,while (sl 祝辞,1,,,,tmpstr.charAt (sl 安康;1),==,& # 39;0 & # 39;) ,sl——; ,if (tmpstr.charAt (sl 安康;1),==,& # 39;# 39;公司) ,sl——; ,if (sl !=, tmpstr.length ()), {=,,tmpstr  tmpstr.substring (0, sl); ,} 其他,}=,,dotpos  sl; ,if (sl & lt;, 1) ,return 数字[0]; ,if (tmpstr.charAt (0),==, & # 39; & # 39;), { ,resstr.append(“负“);=,sp 1; ,} ,String integerNum =, tmpstr.substring (sp, dotpos 作用;sp); ,String decimalNum =,““ ,if (dotpos +, 1, & lt;, sl)=,,decimalNum  tmpstr.substring (dotpos +, 1);=,,sl  integerNum.length ();=,sp 0; ,while (sp & lt;, sl ,,, integerNum.charAt (sp),==, & # 39; 0 & # 39;) ,sp + +; ,if (sp 祝辞,0)=,,integerNum  integerNum.substring (sp); ,int inl =, integerNum.length (); ,if (inl 祝辞,0),{ ,int h =, (inl 安康;1),%,4; ,int j =, (inl 安康;1),/,4,+,1;=,sp 0; ,boolean allzero =,假; ,boolean preallzero =,假; ,for (j 才能;祝辞,0;,j -), { ,int k =, h;=,h 3; ,boolean preiszero =, allzero;=,allzero 真实; ,for (k 才能;祝辞=,0;,k———, sp + +), { ,if (integerNum.charAt (sp),==, & # 39; 0 & # 39;)=,preiszero 真实; ,else {=,allzero 假; ,if (preiszero) ,resstr.append(“零“);=,preiszero 假; ,resstr.append(((字节),(integerNum.charAt (sp)),安康;48]).append (CBit [k]); ,} }大敌; ,//最终获得for k ,if (/*, j !=0,,,, */, j %, 2,==, 0), { ,if (allzero !) ,resstr.append(“万“); ,}else { ,if (! allzero | |, ! preallzero), { ,int repyi =, j /, 2; ,for (int 小姐:=,0;,小姐:& lt;, repyi;,我+ +) ,resstr.append(“亿“); ,} ,}=,,preallzero  allzero; }大敌; ,//最终获得for j 其他,} ,resstr.append(“零“); ,int dnl =, decimalNum.length (); ,if (dnl 祝辞,0),{ ,resstr.append(“点“); ,for (int 小姐:=,0;,小姐:& lt;,黑暗;,我+ +),{ ,resstr.append(((字节),(decimalNum.charAt(我)),安康;48]); ,} ,} ,return resstr.toString (); ,}/* * ,*获得某一位上的数的值,如果,nBit<0,则获得小数点后面的位数 ,*/,static public  char getNumByte (String szNum, int nBit), { ,int sl =, szNum.length (); ,int nPos =, 0; ,while (nPos & lt;, sl ,,, szNum.charAt(非营利组织),!=,& # 39;# 39;公司) ,非营利组织+ +; ,if (nBit & lt;, 0)=,,nPos  nPos 作用;nBit; 其他的,=,,nPos  nPos 作用;nBit 作用;1; ,if (nPos & lt;, 0, | |, nPos 祝辞=,sl) ,return & # 39; 0 & # 39;; ,return szNum.charAt(非营利组织); ,} null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null使用java怎么将数字转换为中文大写的人民币