回 帖 发 新 帖 刷新版面

主题:前辈请帮帮忙,金额怎么转换成大写!

例如:  78.20 变成大写就是  七十八元贰角整!


请大家帮帮我!

回复列表 (共1个回复)

沙发

/*======================================*/
// 小写转换成大写 string=f_get_money(miney)
//  入口参数:money  Double  数字金额
//  返回参数类型: String 汉字大写金额
//作者:钟诚http://www.cnmis.net
/*======================================*/
string Num[0 to 9] = { &
  "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }
string grade[12] = { &
"拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟" }

Ulong good
int tail,code = 0
Double temp

if money >= 0 then 
code = 1
else
money = - money
code = 0
end if
//本段采用递归调用,使得数值精度从4,294,976,295扩大到29,999,999,999,999.98
if money>29999999999999.98 then return'ERROR:This double too big,Convert error!'
Ulong good1
string str_1
int bz=0
if money>=100000000 then
good1=money/100000000
money=money -good1*100000000
   str_1=f_get_money(good1)
str_1=left(str_1,pos(str_1,'元',1) -1)+'亿'
if long(money)<10000000 and long(money)<>0 then str_1=str_1+'零'
if long(money)=0 then str_1=str_1+'元整'
   bz=1 
end if
//
money += 0.005
good = money
temp = money - good
tail = temp*100

if good = 0 AND tail = 0 and bz=0 then
return ""
end if

string result[40]
int ptr, n

ptr = 1
result[ptr] = "整"; ptr++;
if tail <> 0 then
n = Mod(tail, 10)
if n <> 0 then
  result [ptr] = "分"; ptr ++;
  result [ptr] = Num[n]; ptr ++;
end if
if tail>=10 then 
  result [ptr] = "角"; ptr++;
  result[ptr] = Num[tail/10]; ptr++;
else
  if good > 0 then
   result[ptr] = Num[0]; ptr++;
  end if
end if
end if

if good = 0 then goto reverse

result[ptr] = "元"; ptr++;

int has_zero = 1
int grade_ptr = 0

do while good > 0
n = Mod(good, 10)
if n<>0 then
  if grade_ptr>0 then
   result[ptr] = grade[grade_ptr]; ptr++
  end if

  result[ptr] = Num[n] ; ptr++

  has_zero = 0
else
  if grade_ptr = 4 OR grade_ptr = 8 then
   result[ptr] = grade[grade_ptr]; ptr ++
   has_zero = 1
  end if
  if has_zero=0 then
   result[ptr] = "零"; ptr ++
   has_zero = 1
  end if
end if

grade_ptr ++
good /= 10
loop

reverse:
string retval = ""

int i
for i = ptr - 1 TO 1 STEP -1
retval = retval + result[i]
next

if code = 0 then retval = '负' + retval

if right(retval,4) <> '元整' then retval = left(retval,len(retval) -2 )
//
if bz=1 then
if left(retval,2)='负' then 
  retval=right(retval,len(retval) -2)
  str_1='负'+str_1
end if
retval=str_1+retval
end if
//
return retval

我来回复

您尚未登录,请登录后再回复。点此登录或注册