Re: ksh shell: convert a string to integer (2957 Views)
Reply
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 1 of 3 (2,967 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
Dennis Handly
Posts: 25,190
Registered: ‎03-06-2006
Message 2 of 3 (2,957 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
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 3 of 3 (2,947 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.