企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 ``` /** * <b>方法描述:</b> 金额转大写 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-12-16 10:18:18 <br/> * * @param inamt * 入参|输入金额|{@link java.lang.Object} * @param chnamt * 出参|大写金额|{@link java.lang.String} * @return 0 失败<br/> * 1 成功<br/> */ @Component(label = "金额转大写", style = "判断型", type = "同步组件", comment = "将输入金额转出乘中文大写金额输出", version = "1.0.0", deprecated = false, author = "admin", date = "2020-12-16 10:18:18") @InParams(param = {@Param(name = "inamt", comment = "输入金额", type = java.lang.Object.class)}) @OutParams(param = {@Param(name = "chnamt", comment = "大写金额", type = java.lang.String.class)}) @Returns(returns = {@Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功")}) @Order(value = 2) public static ResultBase P_amt2Chn(Object inamt) { BigDecimal numberOfMoney = transform(inamt); if (numberOfMoney == null) return ResultBase.newFailureResult("TPTA0004", "输入不是合法金额数据,输入数据:" + inamt); String[] CN_UPPER_NUMBER = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; String[] CN_UPPER_MONETRAY_UNIT = {"分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟"}; String CN_FULL = "整"; String CN_NEGATIVE = "负"; int MONEY_PRECISION = 2; String CN_ZEOR_FULL = "零元" + CN_FULL; StringBuffer sb = new StringBuffer(); int signum = numberOfMoney.signum(); if (signum == 0) { return ResultBase.newSuccessResult(CN_ZEOR_FULL); } long number = numberOfMoney.movePointRight(MONEY_PRECISION).setScale(0, 4).abs().longValue(); long scale = number % 100; int numUnit = 0; int numIndex = 0; boolean getZero = false; if (!(scale > 0)) { numIndex = 2; number = number / 100; getZero = true; } if ((scale > 0) && (!(scale % 10 > 0))) { numIndex = 1; number = number / 10; getZero = true; } int zeroSize = 0; while (true) { if (number <= 0) { break; } numUnit = (int)(number % 10); if (numUnit > 0) { if ((numIndex == 9) && (zeroSize >= 3)) { sb.insert(0, CN_UPPER_MONETRAY_UNIT[6]); } if ((numIndex == 13) && (zeroSize >= 3)) { sb.insert(0, CN_UPPER_MONETRAY_UNIT[10]); } sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]); sb.insert(0, CN_UPPER_NUMBER[numUnit]); getZero = false; zeroSize = 0; } else { ++zeroSize; if (!(getZero)) { sb.insert(0, CN_UPPER_NUMBER[numUnit]); } if (numIndex == 2) { if (number > 0) { sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]); } } else if (((numIndex - 2) % 4 == 0) && (number % 1000 > 0)) { sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]); } getZero = true; } number = number / 10; ++numIndex; } if (signum == -1) { sb.insert(0, CN_NEGATIVE); } if (!(scale > 0)) { sb.append(CN_FULL); } return ResultBase.newSuccessResult(sb.toString()); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/0d/ed/0ded4ae2c6e55fd5dc5544e1080677db_1871x867.png) # 参数说明及示例 ## 入口参数 输入金额:输入一个数值类型或者字符串类型的数值,示例: `"1,562.26"` ## 出口参数 大写金额:把金额转换为汉字大写表示,示例: `__INNER__["result"]`