function trans(number as string) as string
dim x as string, y as string
x = split(number, ".")(0)
const upcase = "○一二三四五六七** 十百千萬十百千萬億十百千萬十百千萬" '定義漢字
if val(x) >= 10 ^ 16 then msgbox "數目太大,無法換算!請輸入一億億以下的數字!", 64, "錯誤提示": exit function '只能轉換一億億以下的數字!
if instr(number, ".") > 0 then
y = split(number, ".")(1)
for i = 0 to 9
y = replace(y, i, mid(upcase, i + 1, 1))
next
y = "點" & y
end if
for i = 1 to len(x)
trans = trans & mid(upcase, mid(x, i, 1) + 1, 1) & mid(upcase, len(x) - i + 11, 1)
next
trans = replace(trans, "○千", "○")
trans = replace(trans, "○百", "○")
trans = replace(trans, "○十", "○")
do while instr(trans, "○○") > 0
trans = replace(trans, "○○", "○")
loop
trans = replace(trans, "○億", "億")
trans = replace(trans, "○萬", "萬")
if val(x) < 20 then trans = replace(trans, "一十", "十")
trans = trim(trans) & y
end function
private sub command1_click()
msgbox trans("67454801211.783450980896")
end sub
一億億以下的阿拉伯數字轉中文的自定義函式
function trans number as string as string dim x as string,y as string x split number,0 const upcase 一二三四五六七 十百千萬十百千萬億十百千萬十百千萬 定義漢字 if val x 10 16 then...
阿拉伯數字轉中文
public class cnuppercaser 供分級轉化的陣列,因為各個例項都要使用所以設為靜態 private static final char series 建構函式,通過它將阿拉伯數字形式的字串傳入 param original public cnuppercaser string o...
中文數字轉阿拉伯數字
這個題與leetcode第13題羅馬數字轉換很相似 13.roman to integer 我開始想用c 處理,進行漢字 個十百千萬 與數字的對應,但是中文字元不屬於ascii碼,直接使用標準類模板裡的string會導致漢字亂碼。所以得使用寬字串wstring和寬字元wchar t 使用stl中的m...