一个JAVA问题,怎么考虑零处理问题?
题目:使用Java语言实现输入人民币小写金额,输出相对应的人民币大写金额的功能。
要求:
使用Java语言。
无需使用数据库。
输入界面和显示界面自定义。
输入方式和显示方式自定义。
输入人民币小写金额最高9,999,999,999,999.99。
输入人民币金额最低0.01。
人民币大写内容为:零、壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿。
人民币单位:分、角、圆。
当输入小写金额没有分、角时需要在大写金额后添加“整”。
例子:
输入:100.00
输出:壹佰圆整
输入:0.01
输出:壹分
输入:9,999,999,999,999.99
输出:玖万玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖圆玖角玖分
输入:1500.08
输出:壹仟伍佰圆零捌分
输入:200.23
输出:贰佰圆贰角叁分
11111,1111,1111.11
------解决方案--------------------给10分你也好意思
------解决方案-------------------- 给大家介绍个技术群
大家一起学习,一起提高
32517199
------解决方案--------------------.
------解决方案--------------------ding
------解决方案--------------------整数和小数分开处理
------解决方案--------------------package test.format;
import java.text.NumberFormat;
import java.util.HashMap;
public class SimpleMoneyFormat {
public static final String EMPTY = " ";
public static final String ZERO = "零 ";
public static final String ONE = "壹 ";
public static final String TWO = "贰 ";
public static final String THREE = "叁 ";
public static final String FOUR = "肆 ";
public static final String FIVE = "伍 ";
public static final String SIX = "陆 ";
public static final String SEVEN = "柒 ";
public static final String EIGHT = "捌 ";
public static final String NINE = "玖 ";
public static final String TEN = "拾 ";
public static final String HUNDRED = "佰 ";
public static final String THOUSAND = "仟 ";
public static final String TEN_THOUSAND = "万 ";
public static final String HUNDRED_MILLION = "亿 ";
public static final String YUAN = "元 ";
public static final String JIAO = "角 ";
public static final String FEN = "分 ";
public static final String DOT = ". ";
private static SimpleMoneyFormat formatter = null;
private HashMap chineseNumberMap = new HashMap();
private HashMap chineseMoneyPattern = new HashMap();
private NumberFormat numberFormat = NumberFormat.getInstance();
private SimpleMoneyFormat() {
numberFormat.setMaximumFractionDigits(4);
numberFormat.setMinimumFractionDigits(2);
numberFormat.setGroupingUsed(false);
chineseNumberMap.put( "0 ", ZERO);
chineseNumberMap.put( "1 ", ONE);
chineseNumberMap.put( "2 ", TWO);
chineseNumberMap.put( "3 ", THREE);
chineseNumberMap.put( "4 ", FOUR);
chineseNumberMap.put( "5 ", FIVE);
chineseNumberMap.put( "6 ", SIX);
chineseNumberMap.put( "7 ", SEVEN);
chineseNumberMap.put( "8 ", EIGHT);
chineseNumberMap.put( "9 ", NINE);
chineseNumberMap.put(DOT, DOT);
chineseMoneyPattern.put( "1 ", TEN);
chineseMoneyPattern.put( "2 ", HUNDRED);
chineseMoneyPattern.put( "3 ", THOUSAND);
chineseMoneyPattern.put( "4 ", TEN_THOUSAND);
chineseMoneyPattern.put( "5 ", TEN);
chineseMoneyPattern.put( "6 ", HUNDRED);
chineseMoneyPattern.put( "7 ", THOUSAND);