Function ldyDX(M)'205个字符
ldyDX = IIf(M > -0.005, "", "负") & IIf(Abs(M) < 0.005, "", Replace(Replace(Replace(Join(Application.Text(Split(Format(Abs(M), "0.00"), "."), Split("[DBNum2] [DBNum2]0角0分")), "元"), "零分", "整"), "零角", ""), "零元", ""))
End Function
居然还可以短一点 200个字符
Function DX(M)'200个字符
DX = IIf(Abs(M) < 0.005, "", Replace(Replace(Replace(Join(Application.Text(Split(Format(M, " 0. 00")), Split("@ [DBNum2];;0 [>9][dbnum2]圆0角0分;[=0]圆整;[dbnum2]圆零0分")), ""), "零分", "整"), "0圆零", ""), "0圆", ""))
End Function
核心语句2 Join(Application.Text(Split(Format(M, " 0. 00")), Split("@ [DBNum2];;0 [>9][dbnum2]圆0角0分;[=0]圆整;[dbnum2]圆零0分")), "")
再细分一些居然又减少6个字符突破200了 08-7-23
突然想到用 a 代替 “”再少4个 刀砍斧剁 再减5个 不知到是否还能减
Function DX(M)'185个字符
DX = IIf(Abs(M) < 0.005, a, Replace(Replace(Replace(Join(Application.Text(Split(Format(M, " 0. 0 0")), Split(" [DBnum2] [DBnum2]圆0角;;圆零 [DBnum2]0分;;整")), a), "零圆零", a), "零圆", a), "零整", "整"))
End Function
核心语句3 Join(Application.Text(Split(Format(M, " 0. 0 0")), Split("@ [DBNum2] [=]圆零;[dbnum2]圆0角 [=]整;[dbnum2]0分")), "")
-捌角贰分 -0.82
-贰分 -0.015
-壹佰圆零贰分 -100.02
壹万圆零贰分 10000.02
贰角整 0.2
壹圆整 0.995
恶补函数的副产品,纯粹的脑力体操。TEXT有如此多秒用!叹服
核心语句 Join(Application.Text(Split(Format(Abs(M), "0.00"), "."), Split("[DBNum2] [DBNum2]0角0分")), "元")
已经完成 X元X角X分 的转换 其他 iif replace 都是对细节的补充。
两年前我写的7 行,又有 gly1126 写的3行,到现在的1 行。欢迎测试挑错
呵呵
附一个 抄自 EXCEL吧 的公式 191字符
=SUBSTITUTE(SUBSTITUTE(TEXT(TRUNC(FIXED(A1)),"[dbnum2]G/通用格式元;负[dbnum2]G/通用格式元;"&IF(A1>-0.5%,,"负"))&TEXT(RIGHT(FIXED(A1),2),"[dbnum2]0角0分;;"&IF(ABS(A1)>1%,"整",)),"零角",IF(ABS(A1)<1,,"零")),"零分","整")