pb 中怎么把数字转换成大写的中文数字
1个回答
2016-07-29 · 知道合伙人软件行家
关注
展开全部
你说的应该是金额转为大写,可以自定义函数来实现
//-----------------------------------------------------------------//
// 函数名称: f_amount_upper
// 功能描述: 将金额转为大写
// 参数说明:ad_amout (金额)
// 返 回 值: 大写金额,String型
// 使用说明:f_amount_upper (ad_amout)
//-----------------------------------------------------------------//
integer li_i
integer li_lendec,li_lenint
integer li_amout_flag
integer li_point
string ls_amount_string
String ls_single
String ls_single_dx
String ls_single_wei
String ls_mw
String ls_single_dx_bak
string ls_dxint[13] = {'元','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟','万'}
String ls_dxdec[2] = {'角','分'}
String ls_sz[13] = {'零','壹','贰','叁','肆','伍','陆','柒','捌','玖',' ',' ',' '}
string ls_amount_uppder
//如果金额为0
IF ad_amout = 0.00 then
ls_amount_uppder = '零元整'
return ls_amount_uppder
ELSE
//如果金额为负数
IF ad_amout < 0.00 then
ad_amout = abs(ad_amout)
li_amout_flag = 1 //标记
END IF
END IF
//将金额转换为字符型
ls_amount_string = string(ad_amout,'#0.00')
//小数点位置
li_point = pos(ls_amount_string,'.')
//获得金额整数位长度
li_lenint = len(mid(ls_amount_string, 1, li_point - 1))
IF li_lenint > 13 THEN
MessageBox('提示信息','整数部分不能超过13位!', StopSign!)
ls_amount_uppder = 'Error'
Return ls_amount_uppder
END IF
//小数部分
IF right(ls_amount_string,2) = '00' then
li_lendec = 0
ELSE
li_lendec = 2
END IF
ls_amount_uppder = ' '
//整数位转换
For li_i = 1 to li_lenint
//按高位依次取单个数字
ls_single = mid(mid(ls_amount_string, 1, li_lenint), li_i,1)
//单个转为人民币大写
ls_single_dx = ls_sz[integer(ls_single) + 1]
//位
ls_single_wei = ls_dxint[li_lenint - li_i +1]
//记录ls_amount_uppder末位
IF ls_amount_uppder <> ' ' then
ls_mw = mid(ls_amount_uppder, len(ls_amount_uppder) - 1 ,2)
ELSE
ls_mw = ' '
END IF
//避免重复写“零”
IF ls_single_dx = '零' and &
(ls_mw = '零' or ls_single_dx = ls_single_dx_bak or &
ls_single_wei = '元' or ls_single_wei = '万' or &
ls_single_wei = '亿') then
ls_single_dx = ''
END IF
IF ls_single = '0' and ls_single_wei<>'元' and ls_single_wei <>'万' &
and ls_single_wei <>'亿' then
ls_single_wei = ''
END IF
IF (ls_single_wei = '元' or ls_single_wei = '万' or ls_single_wei = '亿') &
and ls_mw = '零' and ls_single = '0' then
ls_amount_uppder = mid(ls_amount_uppder,1,len(ls_amount_uppder) - 2)
ls_mw = mid(ls_amount_uppder,len(ls_amount_uppder) - 1,2)
IF (ls_single_wei = '元' and ls_mw = '万' or &
ls_single_wei = '万'and ls_mw = '亿') then
ls_single_wei = ''
END IF
END IF
ls_amount_uppder = ls_amount_uppder + ls_single_dx + ls_single_wei
//记录
ls_single_dx_bak = ls_single_dx
NEXT
//小数位转换
FOR li_i = 1 to li_lendec
ls_single = mid (mid(ls_amount_string, li_lenint+2, li_lendec),li_i,1)
IF ls_single = '0' and ls_dxdec[li_i] = '分' then
ls_single_dx = ''
ELSE
ls_single_dx = ls_sz[integer(ls_single) + 1]
END IF
IF ls_single <> '0' then
ls_amount_uppder = ls_amount_uppder + ls_single_dx + ls_dxdec[li_i]
ELSE
ls_amount_uppder = ls_amount_uppder+ ls_single_dx
END IF
NEXT
IF li_lendec = 0 then ls_amount_uppder = ls_amount_uppder + '整'
//小于1元的金额
IF ad_amout < 1.00 then ls_amount_uppder = '零' + trim(ls_amount_uppder )
//负数
IF li_amout_flag = 1 then ls_amount_uppder = '负' + ls_amount_uppder
//返回
return ls_amount_uppder
//-----------------------------------------------------------------//
// 函数名称: f_amount_upper
// 功能描述: 将金额转为大写
// 参数说明:ad_amout (金额)
// 返 回 值: 大写金额,String型
// 使用说明:f_amount_upper (ad_amout)
//-----------------------------------------------------------------//
integer li_i
integer li_lendec,li_lenint
integer li_amout_flag
integer li_point
string ls_amount_string
String ls_single
String ls_single_dx
String ls_single_wei
String ls_mw
String ls_single_dx_bak
string ls_dxint[13] = {'元','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟','万'}
String ls_dxdec[2] = {'角','分'}
String ls_sz[13] = {'零','壹','贰','叁','肆','伍','陆','柒','捌','玖',' ',' ',' '}
string ls_amount_uppder
//如果金额为0
IF ad_amout = 0.00 then
ls_amount_uppder = '零元整'
return ls_amount_uppder
ELSE
//如果金额为负数
IF ad_amout < 0.00 then
ad_amout = abs(ad_amout)
li_amout_flag = 1 //标记
END IF
END IF
//将金额转换为字符型
ls_amount_string = string(ad_amout,'#0.00')
//小数点位置
li_point = pos(ls_amount_string,'.')
//获得金额整数位长度
li_lenint = len(mid(ls_amount_string, 1, li_point - 1))
IF li_lenint > 13 THEN
MessageBox('提示信息','整数部分不能超过13位!', StopSign!)
ls_amount_uppder = 'Error'
Return ls_amount_uppder
END IF
//小数部分
IF right(ls_amount_string,2) = '00' then
li_lendec = 0
ELSE
li_lendec = 2
END IF
ls_amount_uppder = ' '
//整数位转换
For li_i = 1 to li_lenint
//按高位依次取单个数字
ls_single = mid(mid(ls_amount_string, 1, li_lenint), li_i,1)
//单个转为人民币大写
ls_single_dx = ls_sz[integer(ls_single) + 1]
//位
ls_single_wei = ls_dxint[li_lenint - li_i +1]
//记录ls_amount_uppder末位
IF ls_amount_uppder <> ' ' then
ls_mw = mid(ls_amount_uppder, len(ls_amount_uppder) - 1 ,2)
ELSE
ls_mw = ' '
END IF
//避免重复写“零”
IF ls_single_dx = '零' and &
(ls_mw = '零' or ls_single_dx = ls_single_dx_bak or &
ls_single_wei = '元' or ls_single_wei = '万' or &
ls_single_wei = '亿') then
ls_single_dx = ''
END IF
IF ls_single = '0' and ls_single_wei<>'元' and ls_single_wei <>'万' &
and ls_single_wei <>'亿' then
ls_single_wei = ''
END IF
IF (ls_single_wei = '元' or ls_single_wei = '万' or ls_single_wei = '亿') &
and ls_mw = '零' and ls_single = '0' then
ls_amount_uppder = mid(ls_amount_uppder,1,len(ls_amount_uppder) - 2)
ls_mw = mid(ls_amount_uppder,len(ls_amount_uppder) - 1,2)
IF (ls_single_wei = '元' and ls_mw = '万' or &
ls_single_wei = '万'and ls_mw = '亿') then
ls_single_wei = ''
END IF
END IF
ls_amount_uppder = ls_amount_uppder + ls_single_dx + ls_single_wei
//记录
ls_single_dx_bak = ls_single_dx
NEXT
//小数位转换
FOR li_i = 1 to li_lendec
ls_single = mid (mid(ls_amount_string, li_lenint+2, li_lendec),li_i,1)
IF ls_single = '0' and ls_dxdec[li_i] = '分' then
ls_single_dx = ''
ELSE
ls_single_dx = ls_sz[integer(ls_single) + 1]
END IF
IF ls_single <> '0' then
ls_amount_uppder = ls_amount_uppder + ls_single_dx + ls_dxdec[li_i]
ELSE
ls_amount_uppder = ls_amount_uppder+ ls_single_dx
END IF
NEXT
IF li_lendec = 0 then ls_amount_uppder = ls_amount_uppder + '整'
//小于1元的金额
IF ad_amout < 1.00 then ls_amount_uppder = '零' + trim(ls_amount_uppder )
//负数
IF li_amout_flag = 1 then ls_amount_uppder = '负' + ls_amount_uppder
//返回
return ls_amount_uppder
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询