当前位置: 首页 > news >正文

报纸网站建设东莞网站推广企业

报纸网站建设,东莞网站推广企业,如何做阿里巴巴国际网站,政府网站建设应用工作方案在金融行业中经常需要把大写金额转成小写金额,之前在一次开发中有个类似的需求,翻阅了好多博文,都没找到合适的,故没办法,就花了点时间研究并实现! 实现代码如下: private static final Character ZERO 零;private s…

在金融行业中经常需要把大写金额转成小写金额,之前在一次开发中有个类似的需求,翻阅了好多博文,都没找到合适的,故没办法,就花了点时间研究并实现!

实现代码如下:

    private static final Character ZERO = '零';private static final String DIME = "角";private static final String CENT = "分";private static final String DOLLAR = "元";private static final String THOUSAND = "万";private static final String HUNDRED_MILLION = "亿";private static final List<Character> unitList = Arrays.asList('圆', '元', '拾', '佰', '仟', '万', '亿');static Map<Char, Integer> numberMap = new HashMap(10) {{put('零', 0);put('壹', 1);put('贰', 2);put('叁', 3);put('肆', 4);put('伍', 5);put('陆', 6);put('柒', 7);put('捌', 8);put('玖', 9);}};static Map<Char, Long> unitZeroMap = new HashMap(7) {{put('亿', 100000000L);put('万', 10000L);put('仟', 1000L);put('佰', 100L);put('拾', 10L);put('元', 1L);put('圆', 1L);}};/*** 把大写金额转换为单位为分的数字*/public static long convertMoneyNum(String money) {// 按亿/万/元(圆)/角/分拆分大写金额List<String> moneyList = buildMoneyList(money);long moneyNum = 0;long centMoneyNum = 0;for (String moneyStr : moneyList) {if (moneyStr.endsWith(DIME)) {centMoneyNum += (numberMap.get(moneyStr.charAt(0)) * 10);  // 大写角转数字分} else if (moneyStr.endsWith(CENT)) {centMoneyNum += numberMap.get(moneyStr.charAt(0));    // 大写分转数字分} else {moneyNum += convertNum(moneyStr);  // 大写亿/万/元(圆)转数字元}}// 返回计算后的数字分return moneyNum * 100 + centMoneyNum;}private static long convertNum(String moneyStr) {char[] chars = moneyStr.toCharArray();Set<Char> unitZeroList = unitZeroMap.keySet();long moneyNumber = 0;int indexNum = 0;int maxIndex = 0;Character preUnit = null;for (int i=0; i<chars.length; i++) {char currNum = chars[i];// 处理字符零if (currNum == ZERO) {preUnit = null;continue;}if (unitZeroList.contains(currNum)) {  // 处理字符为单位long unitNum = unitZeroMap.get(currNum);if (preUnit != null) {moneyNumber = moneyNumber * unitNum;preUnit = null;} else {int currIndex = unitList.indexOf(currNum);if (currIndex > maxIndex) {maxIndex = currIndex;moneyNumber = (moneyNumber + indexNum) * unitNum;} else {moneyNumber = moneyNumber + indexNum * unitNum;}preUnit = currNum;}} else {indexNum = numberMap.get(currNum);  // 处理字符为数字if (i == chars.length-1) {  // 最后一个字符为数字moneyNumber = moneyNumber + indexNum;}preUnit = null;}}return moneyNumber;}private static List<String> buildMoneyList(String money) {List<String> moneyList = new ArrayList<>();int startIndex = 0;// 亿if (money.contains(HUNDRED_MILLION)) {startIndex = buildMoneyList(HUNDRED_MILLION, moneyList, money, startIndex);}// 万if (money.contains(THOUSAND)) {startIndex = buildMoneyList(THOUSAND, moneyList, money, startIndex);}// 元if (money.contains(DOLLAR)) {startIndex = buildMoneyList(DOLLAR, moneyList, money, startIndex);}// 角if (money.contains(DIME)) {startIndex = buildMoneyList(DIME, moneyList, money, startIndex);}// 分if (startIndex < money.length()) {moneyList.add(money.substring(startIndex));}return moneyList;}private static int buildMoneyList(String unit, List<String> moneyList, String money, int startIndex) {int endIndex = money.indexOf(unit) + 1;moneyList.add(money.substring(startIndex, endIndex));return endIndex;}

已有好多年没写过博文了,今天记录哈!!!!

http://www.tj-hxxt.cn/news/48813.html

相关文章:

  • 设计了网站首页成都seo技术
  • 做礼品建什么网站武汉seo网站优化排名
  • 高档餐厅包房装修效果图浙江seo公司
  • 建设网站能挣钱吗建站企业网站
  • 高手做网站优化手机性能的软件
  • 怎么制作游戏私服排名轻松seo 网站
  • 邯郸网站维护线上推广100种方式
  • 免费开网店是真的吗seo交流网
  • 潍坊专业网站建设怎么收费徐州网站建设
  • 网站建设总结报告百度帐号注册
  • dedecms确定网站风格seo网站推广经理招聘
  • 做网站济南西百度搜索风云榜人物
  • 专业网站建设怎么样北京百度推广代理
  • 菜鸟教程网站开发新乡网站优化公司
  • 徐州做网站哪个好市场调研报告包括哪些内容
  • 在网站建设会议上的讲话电视剧百度搜索风云榜
  • 门户网站开发项目的风险游戏广告联盟平台
  • 广州网络兼职网站建设百度网盘下载电脑版官方下载
  • nas 可以做网站吗天津seo推广软件
  • 3gb2c.com是什么网站郑州seo优化大师
  • 外贸建站效果百度网站域名注册
  • 在云服务器上搭建网站内容营销的4个主要方式
  • 崇信县门户网站首页百度推广营销页
  • 微信网站设计运营网络营销的工具有哪些
  • 如何做幼儿园网站设计北京十大营销策划公司
  • 上海工作室宁德seo公司
  • 深圳专业建网站公司专业seo网络营销公司
  • 网站建设开发计入二级科目明细免费注册域名网站
  • python做网站服务器操作系统搜索引擎大全排名
  • 一级水蜜桃宁波seo搜索引擎优化