请高手麻烦帮看一下,问题到底出在什么地方?要求是:¥1245.33。但实际是:1245.3¥或者是:¥ 1245.33.
string ld_value,ld_value01,ld_value02,ld_value03,ls_word
dec LD_NUM,LD_NUM1,LD_NUM2,LD_NUM3
long ll_count_id,L_J
integer al_row
STRING LS_VALUE,ls_xs,ls_sz,ls_col,LS_ZS,LS_TEMP
long ll_len,j,ll_pos
BOOLEAN LB_LEN1
LB_LEN1=TRUE
al_row = dw_base.getrow()
//得到数据窗口的列名
string ls_column_name
ls_column_name = dw_base.describe("#" + string(L_J) + ".Name")
//--------------------------------------------------------------//
//以下程序段设置paymoney列的显示格式
ld_num = dw_base.GetItemNumber(al_row,"paymoney")
If ld_num > 0 then
LS_VALUE = STRING(ld_num,"#0.00")
ll_pos = pos(ls_value,".") //查找字符串中小数点的位置
//以下程序段确保两位小数
if ll_pos>0 then
ls_xs = right(ls_value,len(ls_value) - ll_pos ) //小数
ls_zs = left(ls_value,ll_pos - 1) //整数
ls_xs = LEFT(LS_XS,2)
if len(ls_xs) = 1 then
ls_xs = ls_xs + "0"
end if
ELSE
LS_XS = "00"
ls_zs = ls_value
end if
LL_LEN = LEN(LS_ZS) //得到字符串的长度
for j = 1 to 9
ls_col = "f_7" + string(j)
dw_1.setitem(al_row,ls_col,ls_sz) //al_row = 1
next
if ll_len = 1 then //EXAM :0.12
LS_SZ = LEFT(LS_ZS,1)
if ls_sz = '0' then
ls_sz = ""
end if
LS_COL = "f_73"
dw_1.setitem(al_row,ls_col,ls_sz)
LB_LEN1 = FALSE
end if
DO while (ll_len > 0 AND LB_LEN1 = TRUE)
LS_SZ = LEFT(LS_ZS,1) //从字符串中得到最左边指定长度的字符
LS_ZS = RIGHT(LS_ZS,LEN(LS_ZS) - 1) //从字符串中得到最右边指定长度的字符
LS_COL = "f_7" + string(ll_len + 2)
dw_1.setitem(al_row,ls_col,ls_sz)
ll_len = len(ls_ZS)
loop
dw_1.setitem(al_row,"f_72",left(ls_xs,1))
dw_1.setitem(al_row,"f_71",right(ls_xs,1))
End IF
//-----------------------------------------------------------------------//
if ll_len < 9 then
LL_LEN = LEN(LS_ZS) //得到字符串的长度
LS_COL ="f_7" + string(LL_LEN - 1)
ls_word = "¥"
// dw_1.setitem(al_row,ls_col,ls_sz) //al_row = 1
dw_1.setitem(al_row,ls_col,ls_word) //al_row = 1
End IF
//-----------------------------------------------------------------------//
------解决方案--------------------
我明白你的意思,你的dw中,有f_71,f_72,f_73...列,用来放数据,你应该有9个列,
分 --- f_79
角 -- f_78
元 -- f_77
.....
百万 -- f_71
其实不用这么复杂,你可以从分位开始放,最后再放一个¥
decimal lc_s //数据
string ls_zs
long ll_Pos,ll_len
string ls_ColName //列名
long ll_col //列位置
//假如数据为123.4
lc_s = 123.4
ls_zs = string(lc_s,'#0.00') //格式化后,保证有二位小数
//字符串长度
ll_len = len(ls_zs)
ll_col = 79 //从f_79开始
//从右向左(从分位开始)
for ll_pos = ll_len to 1 step -1
ls_ColName = "f_" + string(ll_col)
dw_1.SetItem(al_row,ls_ColName,Mid(ls_zs,ll_pos,1))
ll_col-- //向左移一位
next
//最后判断,是否写到f_71列,
//如果写到f_71列,就不用加¥
//如果没写到f_71列,就加¥
if ll_col>=71 then
ls_ColName = "f_" + string(ll_col)
dw_1.SetItem(al_row,ls_ColName,"¥")
end if