Compare integer value with decimal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare integer value with decimal
# 1  
Old 07-24-2007
Question Compare integer value with decimal

Hi all,
I have a issue... Is it possible to compare integer value with decimal value.
If it is not possible,then how can i compare 2 decimal values in born shell.thanks!
# 2  
Old 07-24-2007
Try using bc.

x=`echo 10 + 11 |bc`
sets x equal to 21

x=`echo 10.5 - 1.3 |bc`
sets x equal to 9.2
# 3  
Old 07-25-2007
One way...
Code:
a=1.2
b=1.1
if awk 'BEGIN{if(0+'$a'>'$b'+0)exit 0;exit 1}'
then
    echo true
else
    echo false
fi

Also check "Similar Threads" at the bottom of this page.
# 4  
Old 07-25-2007
Question Thanks!

Thanks Jgt & Ygor for replying my query.I will try and see.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

Hi guys... I am loving this integer maths thing. 64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform. Using one of the 'Brothers' methods, URL inside the code. #!/bin/sh # # #!/usr/local/bin/dash # e_constant.sh # Brother's formula . #... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Column value can be Two integer post decimal or blank

Hi Experts, Need your advice. I have a csv file in which column value can contain two integer post decimal(like 1.00, 13.00,12.15, 2.43) or blank. Tried the below code but not working. awk -F "|" '{ if ($39 !~ /^+\.{2}$ || $39 != "") {print "165: Quantity decimal values are not correct... (2 Replies)
Discussion started by: as7951
2 Replies

3. Shell Programming and Scripting

How compare decimal values?

I have 2 files say tp1.txt and tp2.txt having following data cat tp1.txt abc,2.20,IN20 acb,3.15,DN10 bca,3,RD10 cat tp2.txt alv,1.00,IN20 aaa,4.05,DD10 abb,5.50,RD12 i want to compare the values on 2nd field of both the file, if value of first tp1.txt is greater than value... (3 Replies)
Discussion started by: ranabhavish
3 Replies

4. Shell Programming and Scripting

[Solved] need to convert decimal to integer

Using below command awk 'NR==FNR{A=$1;next} {sum+=($2*A)}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt answer:351770174.00000 how to convert this to 351770174. when i try with below command i am getting different result. awk 'NR==FNR{A=$1;next}... (3 Replies)
Discussion started by: katakamvivek
3 Replies

5. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

6. Shell Programming and Scripting

truncate string to integer or decimal

From strings stored in variables, I need to isolate and use the first numerical value contained within them. I will need to know how to produce an integer as well as a floating point decimal. It needs to work on any string regardless of what types of characters (if any) are preceding or following... (3 Replies)
Discussion started by: bradlecat
3 Replies

7. UNIX for Dummies Questions & Answers

compare decimal and integer values in if in bash shell

i need to do camparisions like the below. For the case when first=10 and second=9.9 the scripts displays process failed. I need to be able to convert the values to integer before doing the comparision. Like 9.9 should be rounded over to 10 before doing comparision. Please advice how can... (3 Replies)
Discussion started by: nehagupta
3 Replies

8. Shell Programming and Scripting

Converting decimal to integer

The shell mentioned below will show a warning if the page takes more than 6 seconds to load. The problem is that myduration variable is not an integer. How do I convert it to integer? myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; ] && echo... (3 Replies)
Discussion started by: shantanuo
3 Replies

9. Shell Programming and Scripting

Converting a decimal into integer

Hi all, I'm trying to convert a decimal number into an integer number; I'm doing this: n=`echo |awk '{ print "'"$mem"'"*10}'` where the variable mem is equal to 3.7 I'd like to obtain 37, but the expression above gives me 30. Help please!!!! thx a lot (4 Replies)
Discussion started by: idro
4 Replies

10. Shell Programming and Scripting

Help: How do I ADD non-integer (decimal) values?

I am trying to create a script that will read from a file two non-integer values (decimals) and add those values together. For example, I want to add 1.51 and -2.37 together and get the sum. Any ideas? Thanks! (2 Replies)
Discussion started by: limshady411
2 Replies
Login or Register to Ask a Question