Visit the LQ Articles and Editorials section
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org how to compare decimals
 User Name Remember Me? Password
 Linux - Software This forum is for Software issues. Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

 08-16-2004, 01:39 PM #1 linuxboy69 Member   Registered: Oct 2003 Distribution: Redhat 9 Posts: 138 Rep: how to compare decimals I am writing a script where I need to check if a decimal number is higher than another given decimal number using an if statement. I have the if setup so far as: if [ \$ -lt 0.02 ]; then ... .. fi since the "-lt" operator only does integer I get an error that looks like this: [: .000066041946411: integer expression expected my second idea is that I should multiply the first number by a thousand and then round it off to create an integer. I googled "round decimal" and I get nothing productive. Can someone help me either compare the decimal number or tell me how I round a decimal? I am guessing that rounding the decimal has something to do with the "bc" command.
 08-16-2004, 02:09 PM #2 Komakino Senior Member   Registered: Feb 2004 Location: Somerset, England Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10 Posts: 1,938 Rep: You could use the arbitrary precision calculator bc if it is installed on the system. It accepts equations like 1.2 < 1.3 and outputs 1 for true or 0 for false. e.g: Code: `bc -q` bc -q starts bc without a welcome message. You can echo expressions to bc from a script and receive the output: Code: `echo "1.2 > 1.3" | bc` gives the result 0. Thus you can include piped input (as above) as part of a script. (in Perl): Code: ```if(`echo \"1.2 > 1.1\" | bc` == 0){ print "Something here..."; }``` Sorry, I don't do much bash scripting, but the principle is the same.
 08-16-2004, 03:43 PM #3 linuxboy69 Member   Registered: Oct 2003 Distribution: Redhat 9 Posts: 138 Original Poster Rep: I tried what you put and it worked. Thank you so much!!

 Thread Tools Search this Thread Search this Thread: Advanced Search

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post novazem Linux - Software 14 12-06-2008 11:22 PM Golradir Programming 14 07-04-2004 01:40 PM danxl Programming 3 11-02-2003 03:14 PM tmoorman Linux - Newbie 2 09-26-2003 02:45 PM WeNdeL Linux - Newbie 0 01-17-2003 01:00 PM

All times are GMT -5. The time now is 07:44 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -
 Advertisement
 My LQ
 Write for LQ LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
 Syndicate Latest Threads   LQ News Twitter: @linuxquestions identi.ca: @linuxquestions Facebook: linuxquestions Google+: linuxquestions