DATA:lv_str TYPE string,
lv_str2 TYPE string,
lv_char TYPE char10,
lv_i TYPE i VALUE 1,
lv_f TYPE p DECIMALS 1 VALUE '1.1'.
lv_str = '1.11'.
lv_char = '1.11'.
"TRUE
IF lv_str = 1.
WRITE: 111.
ENDIF.
"string 和 char 一样
" string和char转为int,会进行四舍五入 Decimal places are rounded commercially
"TRUE
IF lv_char = 1.
WRITE: 111.
ENDIF.
lv_str2 = '1.66'.
"FALSE
IF lv_str2 = 1.
WRITE: 111.
ENDIF.
"TRUE
IF lv_str = lv_i.
WRITE:222.
ENDIF.
"如果lv_f = 1.10 type p decimal 2 false
" lv_f = 1.1 type p decimal 1 true
" lv_f = 1.1 type p decimal 2 false
"TRUE
IF lv_str = lv_f.
WRITE:333.
ENDIF.
"解决办法
"1/使用算术表达式代替逻辑表达式
"FALSE
IF + lv_str = 1.
WRITE: 444.
ENDIF.
"2/ 强转
"FALSE
IF lv_str = CONV decfloat16( 1 ).
WRITE: 555.
ENDIF.
| decfloat16, decfloat34 | f | p | int8 | i, s, b |
.--------------|------------------------|---|---|------|---------|
| string, c, n | decfloat34 | f | p | int8 | i |
标签:类型转换,WRITE,char,string,数据类型,lv,ABAP,str,ENDIF
From: https://www.cnblogs.com/sizuru-blog/p/18342549