public class class1 dim strbig(10) as string dim strunit(6) as string private function **alltobig(byval number as decimal) as string try strbig(0) = "零" strbig(1) = "壹" strbig(2) = "貳" strbig(3) = "叄" strbig(4) = "肆" strbig(5) = "伍" strbig(6) = "陸" strbig(7) = "柒" strbig(8) = "捌" strbig(9) = "玖" strbig(10) = "拾"
strunit(0) = "" strunit(1) = "拾" strunit(2) = "佰" strunit(3) = "千" strunit(4) = "萬" strunit(5) = "億" strunit(6) = "兆"
dim strnumber as string = number.tostring dim strend as string = ""
if strnumber.indexof(".") > -1 then strnumber = strnumber.substring(0, strnumber.indexof(".")) strend = number.tostring.replace(strnumber, "").replace(".", "") end if dim count as integer = 0 dim rnumber as string = "" dim str as string = "" do while (math.floor(strnumber.length / 4) - count) >= 0 str = _fournumber(strnumber.substring(iif(strnumber.length - (count + 1) * 4 < 0, 0, strnumber.length - (count + 1) * 4), iif(strnumber.length - (count + 1) * 4 < 0, strnumber.length - count * 4, 4))) if count = 1 then if str.length <> 0 then str += "萬" end if elseif count = 2 then if str.length <> 0 then str += "億" end if elseif count >= 3 then if str.length <> 0 then str += "兆" end if end if rnumber = str + rnumber count += 1 loop
'小數 if strend.length = 1 then strend = strbig(cint(strend)) + "角" elseif strend.length = 2 then if cint(strend).tostring.length = 1 then strend = strbig(cint(strend)) + "分" else strend = strbig(cint(strend.substring(0, 1))) + "角" + strbig(cint(strend.substring(1, 1))) + "分" end if end if
return rnumber + "元" + strend catch ex as exception return "" end try end function private function _fournumber(byval strnum as string) as string try dim count as integer = 0 dim i as integer dim rnum as string = "" dim str as string = "" for i = strnum.length - 1 to 0 step -1 str = strbig(strnum.substring(i, 1)) if str = "零" then rnum = str + rnum else rnum = str + strunit(count) + rnum end if count += 1 next do while rnum.indexof("零零") > -1 rnum = rnum.replace("零零", "零") loop if microsoft.visualbasic.right(rnum, 1) = "零" then rnum = rnum.substring(0, rnum.length - 1) end if return rnum catch ex as exception return "" end try end function end class
金額小寫變大寫 VB版本
金額小寫變大寫 public shared function gmoney smallnum as decimal as string dim cmoney,cnumber,cnum,cnum end,cmon,cno,snum,sno as string dim snum len,sint len...
數字金額轉為大寫金額
金額轉大寫 public class moneyconvertchinese string strlower null string strupart null string strupper null int itemp 0 保留兩位小數 123.489 123.49 123.4 123.4 lo...
數字金額轉化大寫金額
數字金額轉化大寫金額 param val string number 字串可包含 和多餘的0 returns 原生方法 如下所示 function convertcurrency money if typeof money string if money maxnum if money 0 轉換為字...