| | |
to convert string to integer value
Please support our Legacy and Other Languages advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2005
Posts: 1
Reputation:
Solved Threads: 0
How to compare a number stored as string to an integer value in shell scripting? Here is what I have,
if [$temp -ge 2.5] then;
when I run the above code, it gives the error as "Integer Expression expected".
Here the temp variable contains the number "3.0" as a string, I want to compare the value of temp is greater or equal to the number 2.5.
How can I do it.
Please reply soon.
Thanks in advance.
Shiva
if [$temp -ge 2.5] then;
when I run the above code, it gives the error as "Integer Expression expected".
Here the temp variable contains the number "3.0" as a string, I want to compare the value of temp is greater or equal to the number 2.5.
How can I do it.
Please reply soon.
Thanks in advance.
Shiva
Try putting quotes around 2.5 and $temp like so:
otherwise set a variable equal to 2.5 and test that:
This may require quotes too so...
These suggestions are based on BASH shell scripting which is what this kind of looks like, so your mileage may vary...
if ["$temp" -ge "2.5"] then;
SOME_VALUE=2.5 if [$temp -ge $SOME_VAULE] then;
These suggestions are based on BASH shell scripting which is what this kind of looks like, so your mileage may vary...
![]() |
Similar Threads
- String to integer conversion (C)
- Convert a string to an integer (PHP)
- Convert string "aA" to a BigInteger (Java)
- Converting String to Integer help (C++)
- String to integer to ascii (C)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: VB 1.0 Toolbar
- Next Thread: MS Batch File Copying
| Thread Tools | Search this Thread |





