1. 概述
1.1 应用场景
Cnmoney函数 在将数字转换为人民币大写时,小数部分只能精确到分,用户希望能够将小数部分精确到厘、毫。
在票据、落款类报表中,想要直接展示金额、数字的中文大写形式,而非人民币形式。
1.2 实现思路
序号 | 示例 | 方案 | 实现效果 |
---|---|---|---|
1 | 转换为中文大写 | 1)整数部分可直接通过 Cnmoney 函数进行转换 2)小数部分组合运用 MAPARRAY、REPLACE 等函数进行替换 3)最后进行拼接即可 | 12 的返回值:壹拾贰 1234.1234 的返回值:壹仟贰佰叁拾肆点壹贰叁肆 注:NUMTO() 函数不支持小数。 |
2 | 转换为人名币大写(精确到厘、毫 ) | 1)Cnmoney 函数精度范围内的数字直接通过该函数进行转换 2)精度外的数字通过 SWITCH、INDEXOF等函数按位取出,单独进行转换 3)最后进行拼接即可 | 12 的返回值:壹拾贰圆整 1234.1234 的返回值:壹仟贰佰叁拾肆圆壹角贰分叁厘肆毫 |
2. 示例一:转换为中文大写
2.1 模板设计
1)新建一张普通报表,右击任意单元格(例如 A1 单元格),输入数值1234.123,如下图所示:
2)选中 B1 单元格,输入公式:IF(FIND(".",A1)>0,CONCATENATE(REPLACE(CNMONEY(LEFT(A1, FIND(".", A1) - 1)), "圆整", ""), "点", REPLACE(MAPARRAY(split(mid(A1, FIND(".", A1) + 1, 100), ""), SWITCH(item, '0', "零", '1', "壹", '2', "贰", "3", "叁", '4', "肆", "5", "伍", "6", "陆", '7', "柒", '8', "捌", '9', "玖")), ",", "")),REPLACE(CNMONEY(A1),"圆整",""))
,如下图所示:
公式说明:
公式 | 说明 |
---|---|
FIND(".",A1)>0 | 是否存在小数 |
REPLACE(CNMONEY(LEFT(A1, FIND(".", A1) - 1)), "圆整", "") | 若存在小数,小数点左边部分通过函数 CNMONEY() 直接转换为中文 |
REPLACE(MAPARRAY(split(mid(A1, FIND(".", A1) + 1, 100), ""), SWITCH(item, '0', "零", '1', "壹", '2', "贰", "3", "叁", '4', "肆", "5", "伍", "6", "陆", '7', "柒", '8', "捌", '9', "玖")), ",", "") | 右边部分通过函数 MAPARRAY() 将具体每一位数字转换成杜对应的大写中文字符 |
CONCATENATE(REPLACE(CNMONEY(LEFT(A1, FIND(".", A1) - 1)), "圆整", ""), "点", REPLACE(MAPARRAY(split(mid(A1, FIND(".", A1) + 1, 100), ""), SWITCH(item, '0', "零", '1', "壹", '2', "贰", "3", "叁", '4', "肆", "5", "伍", "6", "陆", '7', "柒", '8', "捌", '9', "玖")), ",", "")) | 左右结果通过函数 CONCATENATE()拼接起来 |
REPLACE(CNMONEY(A1),"圆整","") | 若不存在小数,直接通过函数 CNMONEY() 转换为中文,并去掉人民币单位即可 |
2.2 效果预览
保存模板,选择分页预览,如下图所示:
2.3 模板下载
点击下载模板:数字转换为中文大写.cpt
3. 示例二:转换为人名币大写(精确到毫)
3.1 模板设计
1)新建一张普通报表,选中任意单元格(例如 A1 单元格),输入数值17.3456,如下图所示:
2)选中 B1 单元格,输入公式:SWITCH(LEN(MID(A1,FIND(".",A1)+1,100)),0,CNMONEY(A1),1,CNMONEY(A1),2,CNMONEY(A1),3,CONCATENATE(CNMONEY(left(A1,LEN(A1)-1)),SWITCH(INDEXOF(A1,
FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘"),4,CONCATENATE(CNMONEY(left(A1,LEN(A1)-2)),,SWITCH(INDEXOF(A1,
FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘"+SWITCH(INDEXOF(A1,FIND(".",A1)+3),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆",
"5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"毫"))
,如下图所示:
公式说明如下:
注:在使用 Cnmoney函数 时,若小数位超过两位(精度超过分),Cnmoney 函数会对数字四舍五入后再转人名币大写。
公式 | 说明 |
---|---|
LEN(MID(A1,FIND(".",A1)+1,100)) | 判断小数部分的位数(精度) |
CNMONEY(left(A1,LEN(A1)-1)) | 为防止 Cnmoney 函数四舍五入,仅取出精度范围内的部分进行转换 |
SWITCH(INDEXOF(A1,FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘") | 精度外的部分通过 Switch 函数进行转换:
|
CONCATENATE(CNMONEY(left(A1,LEN(A1)-1)),SWITCH(INDEXOF(A1,FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘") | 通过 CONCATENATE 函数将以上两步转换后的内容拼接在一起 |
CONCATENATE(CNMONEY(left(A1,LEN(A1)-2)),,SWITCH(INDEXOF(A1,FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘"+SWITCH(INDEXOF(A1,FIND(".",A1)+3),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"毫") | 同理可将小数第四位(厘)上的数字转换为人民币大写 |
SWITCH(LEN(MID(A1,FIND(".",A1)+1,100)), 0,CNMONEY(A1), 1,CNMONEY(A1), 2,CNMONEY(A1), 3,CONCATENATE(CNMONEY(left(A1,LEN(A1)-1)),SWITCH(INDEXOF(A1,FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘"), 4,CONCATENATE(CNMONEY(left(A1,LEN(A1)-2)),,SWITCH(INDEXOF(A1,FIND(".",A1)+2),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"厘"+SWITCH(INDEXOF(A1,FIND(".",A1)+3),'0',"零",'1',"壹",'2',"贰","3","叁",'4',"肆","5","伍","6","陆",'7',"柒",'8',"捌",'9',"玖")+"毫")) | 通过 SWITCH 函数,根据小数部分的位数选择对应的转换方式:
|
3.2 效果预览
保存模板,选择分页预览,如下图所示:
3.3 模板下载
点击下载已完成模板:数字转换为人民币大写(精确到毫).cpt