阿拉伯数字转换成中文大写

上传人:宝路 文档编号:22319460 上传时间:2017-11-26 格式:DOCX 页数:6 大小:16.19KB
返回 下载 相关 举报
阿拉伯数字转换成中文大写_第1页
第1页 / 共6页
阿拉伯数字转换成中文大写_第2页
第2页 / 共6页
阿拉伯数字转换成中文大写_第3页
第3页 / 共6页
阿拉伯数字转换成中文大写_第4页
第4页 / 共6页
阿拉伯数字转换成中文大写_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《阿拉伯数字转换成中文大写》由会员分享,可在线阅读,更多相关《阿拉伯数字转换成中文大写(6页珍藏版)》请在金锄头文库上搜索。

1、package com.gwt.client.test;/caiquanhui-20120105public class NumberToChinese private final static String a_strNumber = 零, 壹, 贰, 叁, 肆,伍, 陆, 柒, 捌, 玖 ;private final static String a_strModify = , 拾, 佰, 仟, 万,拾, 佰, 仟, 亿, 拾, 佰, 仟 ;private final static String strSign = 负 ;/ 实际上”+“ 号永远都不可能出现.private final st

2、atic String strDot = 点 ;/* 功能: 提取符号位. 说明: 如果输入参数是 -13.3 ,调用该函数的返回值是 负 ; 如果输入参数是 13.3 ,* 调用该函数的返回值是 (空值).* * param pValue* */static private String getSign(String pValue) return pValue.indexOf(-) = 0 ? 负 : ;/* 功能:返回小数部分的汉字 说明:如果输入数据是 12.35,调用该函数返回值是 叁伍* * param pValue* return*/static private String ge

3、tFraction(String pValue) String strFraction = null;/ 用来保存小数部分的数字串int intDotPos = pValue.indexOf(.);if (intDotPos = -1)/ 没有小数部分.return ;strFraction = pValue.substring(intDotPos + 1).trim();StringBuffer sbResult = new StringBuffer(strFraction.length();/ 开始翻译.for (int i = 0; i strFraction.length(); i+)

4、sbResult.append(a_strNumberInteger.parseInt(String.valueOf(strFraction.charAt(i);return sbResult.toString();/* 功能: 返回整数部分的汉字. 如果输入参数是: 234.3,调用该函数的返回值是 贰佰叁拾肆.* param pValue* return*/static private String getInteger(String pValue) String strInteger = null;/ 用来保存整数部分数字串int intDotPos = pValue.indexOf(.

5、);/ 记录 . 所在位置int intSignPos = pValue.indexOf(-);if (intDotPos = -1)intDotPos = pValue.length();strInteger = pValue.substring(intSignPos + 1, intDotPos);/ 取出整数部分/ 反转整数部分数据strInteger = new StringBuffer(strInteger).reverse().toString().trim();/ -/ 开始翻译:StringBuffer sbResult = new StringBuffer();for (in

6、t i = 0; i strInteger.length(); i+) sbResult.append(a_strModifyi);/ System.out.println(String.valueOf(strInteger.charAt(i);/System.out.println(a_strNumberInteger.parseInt(String.valueOf(strInteger.charAt(i);sbResult.append(a_strNumberInteger.parseInt(String.valueOf(strInteger.charAt(i);/ System.out.

7、println(a_strNumberstrInteger.charAt(i) - 48);/ sbResult.append(a_strNumberstrInteger.charAt(i) - 48);sbResult = sbResult.reverse();/ 这个时候得到的结果不标准,需要调整./ 203 返回值是 贰佰零拾三个 正确答案是 贰佰零三/ -/ 串调整.replace(sbResult, 拾零, 拾);replace(sbResult, 零拾, 零);replace(sbResult, 零佰, 零);replace(sbResult, 零仟, 零);replace(sbR

8、esult, 零万, 万 );replace(sbResult, 零亿, 亿 );/ replace(sbResult, 零拾 , 零 );/ replace(sbResult, 零佰 , 零 );/ replace(sbResult, 零仟 , 零 );/ replace(sbResult, 零万 , 万 );/ replace(sbResult, 零亿 , 亿 );/ 多个”零“调整处理replace(sbResult, 零零, 零);replace(sbResult, 零零零 , 零 );replace(sbResult, 零零零零万 , );/ 这两句不能颠倒顺序replace(sbR

9、esult, 零零零零 , );replace(sbResult, 壹拾亿 , 拾亿 );/ 这样读起来更习惯.replace(sbResult, 壹拾万 , 拾万 );/ -if (sbResult.charAt(sbResult.length() - 1) = 零& sbResult.length() != 1)/ 删除个位上的零sbResult.deleteCharAt(sbResult.length() - 1);if (strInteger.length() = 2) replace(sbResult, 壹拾 , 拾 );return sbResult.toString();/ 将结

10、果反转回来./* 功能: 返回分割符号 如果参数是 12.3 调用该函数的返回值是 点 如果参数是 12 调用该函数的返回值是 (空值)* * param pValue* return*/static private String getDot(String pValue) return pValue.indexOf(.) != -1 ? 点 : ;/ 数字到汉字static public String NumberToChinese(double pValue) / 注意:不能用 string.valueOf(pValue)处理,你自己试试就知道了.java.text.DecimalForm

11、at df = new java.text.DecimalFormat(#.# );String pTemp = String.valueOf(df.format(pValue);StringBuffer sbResult = new StringBuffer(getSign(pTemp)+ getInteger(pTemp) + getDot(pTemp) + getFraction(pTemp);return sbResult.toString();/* 功能:用给定字符串 pDest 替换字符串 pValue 中的 pSource* * param pValue* param pSour

12、ce* param pDest* return 经过替换处理的字符串 例:pValue= xy ,pSource =x ,pDest = 测试 调用改函数后 pValue =测试 y* * 说明一下: 如果 pvalue= xxx pSource = xx 处理结果是 x* ,这个结果可能与您平时看到的替换函数有点不一样,通常应该是 pSource =xx.* */static private void replace(StringBuffer pValue, String pSource,String pDest) if (pValue = null | pSource = null | p

13、Dest = null)return;int intPos = 0;/ 记录 pSource 在 pValue 中的位置do / -/ intPos = pValue.toString().indexOf(pSource,intPos);/ -/ =intPos = pValue.toString().indexOf(pSource);/ =if (intPos = -1)/ 没有找到 pSource.break;pValue.delete(intPos, intPos + pSource.length();pValue.insert(intPos, pDest);/ -/ intPos += pSource.length();/ - while (true);/ 现在发现这样的处理没有什么实际意义。所以我就不写了.public String ChineseToNumber(String pValue) return null;public static void main(String args) / 为了方便您看程序运行结果,我将所有方法都设置成静态的/ 测试:System.err.println(0.34);System.err.println(NumberToChinese(0.34);System.err.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号