Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org how to compare decimals
 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, 12: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, 01: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, 02: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!!

 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 10:22 PM Golradir Programming 14 07-04-2004 12:40 PM danxl Programming 3 11-02-2003 02:14 PM tmoorman Linux - Newbie 2 09-26-2003 01:45 PM WeNdeL Linux - Newbie 0 01-17-2003 12:00 PM

All times are GMT -5. The time now is 02:33 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -