分享 Power Query 中转换大写金额函数
分享自己编写的转换大写金额函数
let
Number.Crmb=(money as number) as text=>
//money:待转换的阿拉伯数字金额
if Number.Abs(money) > 10000000000000 then "数字过大,本函数不支持"
else if money = 0 then "零元整"
else [
cnum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分",
snum = Text.From(Number.Round(Number.Abs(money)*100)),
len = Text.Length(snum),
m = List.Transform({0..(len-1)}, each Text.Combine({Text.Middle(cnum, Number.FromText(Text.Middle(snum, _ , 1)), 1), Text.Middle(cnum, 26 - len + _ , 1)})),
r0 = Text.Combine(m),
r1 = {{"零仟", "零"}, {"零佰", "零"}, {"零拾", "零"}, {"零零", "零"}, {"零零", "零"}, {"零亿", "亿"}, {"零万", "万"}, {"零元", "元"}, {"亿万", "亿"}, {"零角", "零"}, {"零分", "整"}, {"零整", "整"}},
r2 = List.Accumulate(r1, r0, (x,y) => Text.Replace(x, y{0}, y{1})),
r3 = if money > 0 then r2 else Text.Combine({"负", r2})
][r3]
in
Number.Crmb
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)