Operating System - HP-UX
1745863 Members
4356 Online
108723 Solutions
New Discussion

Re: ksh shell: convert a string to integer

 
SOLVED
Go to solution
support_billa
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

2 REPLIES 2
Dennis Handly
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%.*}

support_billa
Valued Contributor
Solution

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