还是要简洁,直接贴代码:
package Num2hanzi; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Num2hanzi { private static String[] hanzinum = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; private static String[] hanziwei = {"","拾","佰","仟"}; private static String[] hanziduan = {"","万","亿"}; private static int num;//输入的数字 private static int duannum = 0; private static int duantemp = 0; private static int[] duan = new int[10]; private static int weinum = 0; private static int weitemp = 0; private static int[] wei = new int[100]; public static void main(String args[]) throws IOException{ //控制台读入数字 num = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()); divideDuanWei(num); System.out.println(convert2hanzi()); } //获取位数长度 public static int getLength(int[] wei){ int length = 0; for(int i=wei.length-1;i>=0;i--){ if(wei[i] == 0){ length++; }else { break; } } length = wei.length - (length--); return length; } //得到最终字符串 public static String convert2hanzi(){ int weilength = getLength(wei); int duanlength = getLength(duan); String convertResult=""; int i=duanlength-1;//段的数目 int j=weilength-1;//位的数目 int k;//起始汉字位 if(weilength%hanziwei.length==0){ k=hanziwei.length - 1; } else { k=weilength%hanziwei.length - 1; } int l = duannum -1;//起始段位 for(;i>=0 && l>=0;i--,l--){ for(;j>=0 && k>=0 ;j--,k--){ if(k==0 && wei[j]==0) continue;//末位为零的时候,省略零 convertResult += hanzinum[wei[j]]; convertResult += hanziwei[k]; } convertResult += hanziduan[l]; k = hanziwei.length - 1; } return convertResult; } public static void divideDuanWei(int num){ if(num>=0){ //分段分位,4个数为一个段,1个数占一个位 duantemp = num; while(duantemp > 0 && duantemp/10000 >= 0){ duan[duannum] = duantemp%10000; weitemp = duan[duannum]; while(weitemp>0 && weitemp/10 >= 0){ wei[duannum*4 + weinum] = weitemp%10; weitemp /= 10; weinum++; } weinum = 0; duantemp /= 10000; duannum++; } } } }
运行结果:
相关推荐
mysql 函数,可以将数字转换为中文大写形式。大写数字是中国特有的数字书写方式,利用与数字同音的汉字取代数字,以防止数目被涂改。 据考证,大写数字最早是由武则天发明,后经朱元璋改进完善。
将数字金额转换为中文大写金额将数字金额转换为中文大写金额将数字金额转换为中文大写金额
读入一个浮点数值,转换为金额大写。整数只显示整数部分。含连续0只输出一个“零”。整圆显示“整”。
excel 纯函数 数字转换大写 数字转换财务大写 数字转换中文 数字转换汉字,里面有详细的介绍,非常适合初学者,操作简单方便,易学易用,希望能给您带来帮助。 适合excel2000及以上版本。
易语言数字转换汉字大写源码,数字转换汉字大写
MySQL函数 数字转中文 非金额 处理数据类型 decimal(21,6)
商业开票时经常对金额等数值用中文大写表示以防止被人篡改。
示例中列出了三种实现在SQL中将日期转换为中文大写的方法,两种通过函数实现,一种通过存储过程实现。
本文实例为大家分享了python实现人民币大写转换的具体代码,供大家参考,具体内容如下 #!/usr/bin/python # -*- coding:utf-8 -*- # ********* 转换方法介绍 ********* # 将需要转换的数字从右向左,每4位分成一个...
输入数字转换为人民币大写,Delphi源代码,代码里有个重要的转换单位,此单位共定义两个函数来实现数字金额的中文大写转化,此函数可支持12位整数。程序思路如下: 将小数点前的整数取出,算出整数长度,不足千亿时...
主要为大家详细介绍了java实现数字转换人民币中文大写工具,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
MoneyFormat 转换成大写中文。
create or replace function sf_get_money(p_num in number default null) 此函数处理数字小写金额转换为大写金额
C语言成序设计__实现人民币小写金额与大写金额的转换
将阿拉伯数字表示的货币数值转换成以中文大写表示的货币数值。可以支持十万元级别和百万元级别。
在记账时,我们经常用大写汉字代替数字进行记账,而我们在数值运算时往往是采用的阿拉伯数字进行的计算,这时我们就需要用到将阿拉伯数值转换成大写金额的数值转换工具,而这篇代码讲的就是这种数值换算运算.
一个用 Oracle 编写货币大写转换(函数不支持转换小数点) 最多可能转换21位数字
excel中将阿拉伯数字转换成中文大写数字的函数方式.docx
sqlserver数字转金额大写,输入数字返回汉字大写
函数输入双精度数值,长度13位,输出字符串,转换位到兆。