小问题:在PB中如何把文本转换成数字。(string to number)

sbm 2002-03-14 01:30:53
小问题:在PB中如何把文本转换成数字。(string to number)
...全文
1908 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbm 2002-03-14
  • 打赏
  • 举报
回复
谢谢,我由于直接用在 IF 中判断,所以报错。
justlove 2002-03-14
  • 打赏
  • 举报
回复
//------------------------------------------
//gf_cm_upper_number(decimal ar_amount) return string
// 参数ar_amount,类型 decimal
// 返回值类型 string
//
//-------------------------------------------
string ls_input
integer li_strlen, li_cursor, li_count
string ls_result, ls_digit
integer li_digit

//String constant
string ls_const_CC_number[] = &
{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}
string ls_const_CC_Unit[] = &
{"", "拾", "佰", "仟","万","拾","佰","仟","亿","拾","佰","仟"}
string ls_yuan = "圆", ls_jiao = "角", ls_fen = "分", ls_negtive = "负"

//Convert the input real value to string
ls_input = string(abs(ar_amount), "0.00")
li_strlen = len(ls_input)

//Generate Integer part
ls_result = ls_yuan
li_count = 0
FOR li_cursor = li_strlen - 3 TO 1 STEP -1
li_count = li_count + 1
ls_digit = mid(ls_input, li_cursor, 1)

//Get the index of the table number
li_digit = Integer(ls_digit)
ls_result = ls_const_CC_number[li_digit + 1] + &
ls_const_CC_Unit[li_count] + ls_result
NEXT

//Generate fragment part
ls_digit = mid(ls_input, li_strlen - 1, 1)
li_digit = Integer(ls_digit)
ls_result = ls_result + ls_const_CC_number[li_digit + 1] &
+ ls_jiao

ls_digit = mid(ls_input, li_strlen , 1)
li_digit = Integer(ls_digit)
ls_result = ls_result + ls_const_CC_number[li_digit + 1] &
+ ls_fen

IF ar_amount < 0 THEN
ls_result = ls_negtive + ls_result
END IF

RETURN ls_result

改动一下就可以了
daiwoo_wang 2002-03-14
  • 打赏
  • 举报
回复
用转换函数,如integer('13')将字符串13转换为整数13,同理,dec()也可。
kelvinma 2002-03-14
  • 打赏
  • 举报
回复
string ls_str
integer li_int

if isnumber(ls_str) then
li_int=integer(ls_str)
end if

字符串转换函数还包括:Double, Dec, Long, Real

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧