Re: ksh shell: convert a string to integer (3652 Views)
Reply
Valued Contributor
Posts: 192
Registered: ‎06-27-2011
Message 1 of 3 (3,662 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

Acclaimed Contributor
Posts: 25,608
Registered: ‎03-06-2006
Message 2 of 3 (3,652 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%.*}

Valued Contributor
Posts: 192
Registered: ‎06-27-2011
Message 3 of 3 (3,642 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

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.