主题:字符型数字转换成中文数字
tjdgweijin
[专家分:0] 发布于 2010-04-21 16:44:00
请教:我是初学者,在用报表打印毕业证时,怎样将出生年月(字符型)字段中的阿拉伯数字转换成中文数字。另外,怎样把系统日期中的数字也转换成中文数字。谢谢
回复列表 (共8个回复)
沙发
dbfox [专家分:490] 发布于 2010-04-21 17:40:00
譬如“1989.02.15”变成“一九八五年二月十五日”
是这样吗?
问问题应该尽量具体些,这样才好回答你!
板凳
dbfox [专家分:490] 发布于 2010-04-21 18:02:00
年份好办,假如你的出生年份为1989年,你的出生年月字段值为“198902”,假如出生年月的字段名为“csny”,那么转换方法如下:
hz = '○一二三四五六七八九十'
hzcsny = '' &&汉字年月
for i = 1 to 6
cc = subs(csny,i,1)
nn = val(cc)
hzcsny = hzcsny +subs(hz,nn*2+1,2)
endfor
hzyear = left(hzcsny,4)
hzmonth = right(hzcsny,2)
do case
case left(hzmonth,2)='○'
hzmonth = right(hzmonth,2)
case hzmonth = '一○'
hzmonth = '十'
case hzmonth = '一一' or hzmonth = '一二'
hzmonth = '十'+right(hzmonth,2)
endcase
hzcsny = hzyear +'年'+hzmonth+'月'
3 楼
dbfox [专家分:490] 发布于 2010-04-21 18:13:00
解二:
hz = '○一二三四五六七八九十'
hzyear = '' &&汉字年月
for i = 1 to 4
hzyear = hzyear +subs(hz,val(subs(csny,i,1))*2+1,2)
endfor
month = val(right(csny,2))
hzmonth = iif(month<11,subs(hz,month*2+1,2),'十'+subs(hz,(month-10)*2+1,2))
hzcsny = hzyear +'年'+hzmonth+'月'
4 楼
dbfox [专家分:490] 发布于 2010-04-22 09:45:00
PARAMETERS csnyr
IF TYPE('csnyr') = 'U' OR TYPE('csnyr')='L'
csnyr = DTOS(DATE())
ENDIF
hz = '○一二三四五六七八九十'
hzyear = '' &&汉字年
for i = 1 to 4
hzyear = hzyear +subs(hz,val(subs(csnyr,i,1))*2+1,2)
ENDFOR
nMonth = val(subs(csnyr,5,2))
hzmonth = iif(nMonth<11,subs(hz,nMonth*2+1,2),'十'+subs(hz,(nMonth-10)*2+1,2))
nDay = VAL(RIGHT(csnyr,2))
hzday = IIF(nDay<11,SUBSTR(hz,nDay*2+1,2),;
IIF(BETWEEN(nDay,11,19),'十'+SUBSTR(hz,(nDay-10)*2+1,2),SUBSTR(hz,INT(nDay/10)*2+1,2)+'十'+SUBSTR(hz,(nDay-INT(nDay/10)*10)*2+1,2)))
hzday = strt(hzday,'○','')
hzcsny = hzyear +'年'+hzmonth+'月'+hzday+'日'
MESSAGEBOX(hzcsny)
5 楼
dbfox [专家分:490] 发布于 2010-04-22 09:56:00
PARAMETERS csnyr
IF TYPE('csnyr') = 'U' OR TYPE('csnyr')='L'
csnyr = DTOS(DATE())
ENDIF
hz = '○一二三四五六七八九十'
hzyear = '' &&汉字年
for i = 1 to 4
hzyear = hzyear +subs(hz,val(subs(csnyr,i,1))*2+1,2)
ENDFOR
nMonth = val(subs(csnyr,5,2))
hzmonth = iif(nMonth<11,subs(hz,nMonth*2+1,2),'十'+subs(hz,(nMonth-10)*2+1,2))
cday = subs(csnyr,7,2)
hzday = SUBSTR(hz,VAL(LEFT(cday,1))*2+1,2) + '十' + SUBSTR(hz,VAL(RIGHT(cday,1))*2+1,2)
hzday = strt(strt(strt(hzday,'○十',''),'十○','十'),'一十','十')
hzcsny = hzyear +'年'+hzmonth+'月'+hzday+'日'
MESSAGEBOX(hzcsny)
6 楼
dbfox [专家分:490] 发布于 2010-04-22 10:04:00
PARAMETERS csnyr
IF TYPE('csnyr') = 'U' OR TYPE('csnyr')='L'
csnyr = DTOS(DATE())
ENDIF
hz = '○一二三四五六七八九十'
hzyear = '' &&汉字年
for i = 1 to 4
hzyear = hzyear +subs(hz,val(subs(csnyr,i,1))*2+1,2)
ENDFOR
nMonth = val(subs(csnyr,5,2))
hzmonth = iif(nMonth<11,subs(hz,nMonth*2+1,2),'十'+subs(hz,(nMonth-10)*2+1,2))
cday = subs(csnyr,7,2)
hzday = SUBSTR(hz,VAL(LEFT(cday,1))*2+1,2) + '十' + SUBSTR(hz,VAL(RIGHT(cday,1))*2+1,2)
hzday = strt(strt(strt(hzday,'○十',''),'十○','十'),'一十','十')
hzcsny = hzyear +'年'+hzmonth+'月'+hzday+'日'
hzcsny =strt(strt(strt(hzcsny,'年○月','年'),'月○日','月'),'年○日','年')
MESSAGEBOX(hzcsny)
7 楼
fyyylyl [专家分:8550] 发布于 2010-04-22 11:09:00
PARAMETERS dDate
SET DATE ANSI
SET CENTURY On
cNum="○一二三四五六七八九十"
cDate=""
FOR I=1 TO 4
cDate=cDate+SUBSTR(cNum,VAL(SUBSTR(Dtos(dDate),I,1))*2+1,2)
ENDFOR
cDate=cDate+"年"+IIF(Month(dDate)<10,"","十")+IIF(Month(dDate)%10=0,"",SUBSTR(cNum,VAL(SUBSTR(Dtos(dDate),6,1))*2+1,2))+"月";
+IIF(Day(dDate)<10,"",IIF(Day(dDate)>19,+SUBSTR(cNum,VAL(SUBSTR(Dtos(dDate),7,1))*2+1,2),"")+"十");
+IIF(Day(dDate)%10=0,"",SUBSTR(cNum,VAL(SUBSTR(Dtos(dDate),8,1))*2+1,2))+"日"
RETURN cDate
8 楼
tjdgweijin [专家分:0] 发布于 2010-04-22 21:05:00
谢谢各位楼主,还有一个问题,这段程序应该放到什么地方?
我来回复