Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integer/Float Problem

Status
Not open for further replies.

danhodges99

IS-IT--Management
Feb 6, 2003
21
GB
Hi,

I have a script which takes a value from a file and performs calculations on it. Trouble is that this value is a float not an integer and it errors at the decimal point!
eg. 94.62
I would like to be able to detect the length of the float (in this above case, 5 characters), and simply do a cut -c on the first x characters depending on it's length. Anyone know how to detect the length of this input?

Cheers
 
No problem guys, got it! In case anyone needs to know, you can just bung the variable into a temp file and do a
wc -m ${TEMPFILE}
which gives you the total characters in the file. Ta anyways.
 
Hi,
if
A=94.62
(for example)
echo ${#A} give 5
I think it is better than create temporary file and count it size.
Regards Boris
 
Another way:

VAR=94.62
len=$(expr "$VAR" : '.*')
echo $len

# or if you prefer:
len=`expr "$VAR" : '.*'`
echo $len

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top