Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

ksh shell: convert a string to integer

SOLVED
Go to Solution
Valued Contributor

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

1 ACCEPTED SOLUTIONS
Highlighted
Valued Contributor

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

2 REPLIES
Acclaimed Contributor Acclaimed Contributor

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%.*}

Highlighted
Valued Contributor

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