midrange.com code scratchpad |
Name:
Using atof() to extract numeric float value
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
09/12/2012 10:22:46 am
|
IP:
Logged
|
|
Description:
Using atof() to extract numeric float value
By Dennis Lovelady, September, 2012
|
Code:
- H BNDDIR('QC2LE') ActGrp(*New) DftActGrp(*No) Option(*SrcStmt)
-
- D atof PR 8F Extproc('atof')
- D string_in * Value Options(*String)
-
- D showme PR 8F ExtProc('showMe')
- D keyIn Value Like(Key)
- D searchMe 80 Const
-
- D myString C 'L=19.3000A=19.43M=21.7700LS=19.93AS'
- D Key S 16 Varying
- D Result S 8F
-
- /Free
-
- result = showme('LS': myString) ;
- dsply %Char(result) ;
- *INLR = *On ;
- Return ;
-
- /End-free
-
- P showme B
- D showme PI 8F
- D keyIn Value Like(key)
- D searchMe 80 Const
-
- D Pos S 10I 0
- D wrkKey S Like(key)
- D rtnVal S Like(showme)
-
- /Free
-
- wrkKey = keyIn + '=' ;
- Pos = %Scan(wrkKey: searchMe) ;
- If Pos < 1 ;
- rtnVal = -1 ;
- Else ;
- Pos += %Len(keyIn) + 1 ;
- rtnval = atof(%Subst(searchMe: Pos)) ;
- EndIF ;
- Return rtnVal ;
-
- /End-free
-
- P showMe E
|
|
|