数字转换成中文汉字
Posted ssdut_yrp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数字转换成中文汉字相关的知识,希望对你有一定的参考价值。
public class NumberUtils
public NumberUtils()
public static final String[] UNITS="","十","百","千","万","十","百","千","亿","十","百","千";
public static final String[] NUMS = "零","一","二","三","四","五","六","七","八","九";
@SuppressWarnings("null")
public static String translate(int value)
String results="";
for(int i=String.valueOf(value).length()-1;i>=0;i--)
int r=(int) (value/(Math.pow(10, i)));
results+=NUMS[r%10]+UNITS[i];
results = results.replaceAll("零[十, 百, 千]", "零");
results = results.replaceAll("零+", "零");
results = results.replaceAll("零([万, 亿])", "$1");
results = results.replaceAll("亿万", "亿"); //亿万位拼接时发生的特殊情况
if(results.startsWith("一十"))
results=results.substring(1);
if(results.endsWith("零"))
results=results.substring(0, results.length()-1);
return results;
public static void main( String[] args )
System.out.println( NumberUtils.translate(100000010) );
以上是关于数字转换成中文汉字的主要内容,如果未能解决你的问题,请参考以下文章