Re: ksh shell: convert a string to integer (1453 Views)
Reply
Valued Contributor
support_billa
Posts: 185
Registered: ‎06-27-2011
Message 1 of 3 (1,463 Views)
Accepted Solution

ksh shell: convert a string to integer

is there another way to convert a string to a integer in shell (KSH)

 

my workaround :

 

var="128.00M"
var=$(  echo ${var} | awk '{print int($0) }' )

 

regards

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,389
Registered: ‎03-06-2006
Message 2 of 3 (1,453 Views)

Re: ksh shell: convert a string to integer

>is there another way to convert a string to a integer in shell (ksh)

 

That type of string?  var="128.00M" is not a numeric value, especially with that "M".

 

If you just want to chop off that "." what follows, you can do:

num=${var%.*}

Please use plain text.
Valued Contributor
support_billa
Posts: 185
Registered: ‎06-27-2011
Message 3 of 3 (1,443 Views)

Re: ksh shell: convert a string to integer

hello,

 

so i can convert with your input :

 

typeset -i num 

var="128.00M"

num=${var%.*}

 

and i will forget the awk

 

regards

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation