人民幣阿拉伯數字轉中文大寫的幾種特殊情況

2021-10-08 01:30:10 字數 2151 閱讀 7801

連著多個『0』讀作乙個「零」

開頭數字是『1』時省略「壹」,如『11』讀作「拾壹」而不是「壹拾壹」

小數為『00』時讀作「整」

小數為『0x』時讀作「x分」

小數為『x0』時讀鎖「x角」

小數為『xx』時讀作「x角x分」

整數部分僅為『1』時,『壹』不省略

整數部分為『0』時,直接讀小數,省略「元」

華為機試人民幣轉換

import re

while

true

:try

: al =

["零"

,"壹"

,"貳"

,"叄"

,"肆"

,"伍"

,"陸"

,"柒"

,"捌"

,"玖"

] de =

["元"

,"拾"

,"佰"

,"仟"

,"萬"

,"拾"

,"佰"

,"仟"

,"億"

,"拾"

,"佰"

,"仟"

,"萬億"

,"拾"

,"佰"

,"仟"

] res =

'人民幣'

shu =

input()

.split(

'.')

data = shu[0]

if shu[0]

[0]==

'0':

res = res

elif shu[0]

[0]==

'1'and

len(shu[0]

)==1:

res = res +

"壹"+

"元"else

:for i in

range

(len

(data)):

iflen

(res)

>

0and res[-1

]=="零"and data[i]

=='0'

:continue

elif data[i]

=='0'

: res = res + al[

int(data[i])]

elif i ==

0and data[i]

=='1'

: res = res + de[

len(data)

- i -1]

else

: res = res + al[

int(data[i])]

+ de[

len(data)

-i-1

] data = shu[1]

if data[0]

!='0'

and data[1]

=='0'

: res = res + al[

int(data[0]

)]+'角'

elif data[0]

=='0'

and data[1]

!='0'

:if shu[0]

[0]==

'0':

res = res + al[

int(data[1]

)]+'分'

else

: res = res + al[

int(data[1]

)]+'分'

elif data[0]

!='0'

and data[1]

!='0'

: res = res + al[

int(data[0]

)]+'角'

+ al[

int(data[1]

)]+'分'

else

: res = res +

'整'print

(res)

except

:break

人民幣阿拉伯數字轉中文大寫

public class money public static string change string p if p.indexof 1 else 如果存在高四位,萬位為0,輸出中轉零,並把整數值加給輸出字串 if cstring.length 0 else 將小數值加給輸出字串 x chang...

php阿拉伯數字轉中文人民幣大寫

1 php阿拉伯數字轉中文人民幣大寫。數字金額轉換成中文大寫金額的函式 string int num 要轉換的小寫數字或小寫字串 return 大寫字母 小數字為兩位 function num to rmb num i 0 c while 1 else 每次將最後一位數字轉化為中文 p1 subst...

js阿拉伯數字轉中文大寫

function dx n if 0 1 9 d d test n return 資料非法 var unit 千百拾億千百拾萬千百拾元角分 str n 00 var p n.indexof if p 0 n n.substring 0,p n.substr p 1,2 unit unit.subst...