1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /**
- *
- * Copyright (c) behosoft Co.,Ltd.
- * All Rights Reserved.
- *
- * This software is the confidential and proprietary information of behosoft.
- * (Social Security Department). You shall not disclose such
- * Confidential Information and shall use it only in accordance with
- * the terms of the license agreement you entered into with behosoft.
- *
- * Distributable under GNU LGPL license by gnu.org
- */
- package com.behosoft.util;
- /**
- * <p>
- * Title: behosoft_[子系统统名]_[模块名]
- * </p>
- * <p>
- * Description: [描述该类概要功能介绍]
- * </p>
- *
- * @author behosoft
- * @version $Revision$ 2012-5-14
- * @author (lastest modification by $Author$)
- * @since 1.0
- */
- public class DigitUpperUtils {
- public static final String fraction[] = { "角", "分" };
- public static final String digit[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- public static final String unit[][] = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
- public static final String sign[] = { "负", "正 " };
- /**
- * <p>
- * Description:[数字金额大写转换,思想先写个完整的然后将如零拾替换成零 要用到正则表达式]
- * </p>
- *
- * @param n
- * @return
- */
- public static String digitUppercase(double n) {
- String head = n < 0 ? sign[0] : "";
- n = Math.abs(n);
- String s = "";
- for (int i = 0; i < fraction.length; i++) {
- s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
- }
- if (s.length() < 1) {
- s = "整";
- }
- int integerPart = (int) Math.floor(n);
- for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
- String p = "";
- for (int j = 0; j < unit[1].length && n > 0; j++) {
- p = digit[integerPart % 10] + unit[1][j] + p;
- integerPart = integerPart / 10;
- }
- s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
- }
- return head
- + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$",
- "零元整");
- }
- public static void main(String[] args) {
- String fee = DigitUpperUtils.digitUppercase(1000000D);
- System.out.println(fee);
- }
- }
|