Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting character to integer

Status
Not open for further replies.

PrintNET

MIS
Sep 30, 2002
30
0
0
US
I want to change a variable that is a numeric character/s to integer form. Also, is it possible to do this if there are spaces in the character string?
 
PrintNET;

lcMyChar = " 87.2"
lnMyNumeric = INT(VAL(ALLTRIM(lcMyChar)))
? lnMyNumeric


Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
NOTE:

val() will convert number string to number

? val("82.5")
will return 82.5 as number

? int(val("82.5"))
will return 82 as the integer of 82.5

? val(alltrim(" 82.5")) will trim any leading and trailing spaces and return 82.5 as number

? val(alltrim(" 8 2.5")) will return 8 as number because val will stop at the first non-numeric char


? val(chrtran(" 8 2.5"," ","")) will transform all " "(spaces) to "" before the val


? val(chrtran(" 8 2.5"," ","")) would best handle spaces inside the number string not just before and after.


Steve Bowman
steve.bowman@ultraex.com

 
forgot if you also want the return to be just the intiger i.e 8 instead of 8.5 then

? int(val(chrtran(" 8 2.5"," ","")))


Steve Bowman
steve.bowman@ultraex.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top