Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

bash: dividing/multiplying variables resulting in decimals

Shell Programming and Scripting


Tags
bash

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-02-2008
puddy's Unix or Linux Image
puddy puddy is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 3 December 2008, 7:44 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
bash: dividing/multiplying variables resulting in decimals

Sponsored Links
    #2  
Old Unix and Linux 12-03-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 July 2015, 11:27 AM EDT
Location: The Netherlands
Posts: 7,731
Thanks: 129
Thanked 546 Times in 514 Posts
If awk is available you can try this:


Code:
score=`awk 'BEGIN{printf("%0.2f", '$CORRECT' / '$PROBLEMS' * 100)}'`

instead of:


Code:
let "score= ( $CORRECT / $PROBLEMS ) * 100"

Regards
Sponsored Links
    #3  
Old Unix and Linux 12-03-2008
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 22 June 2015, 10:58 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,356
Thanks: 85
Thanked 163 Times in 149 Posts
Hammer & Screwdriver Another way to solve


Code:
score=`echo $CORRECT*100/$PROBLEMS | bc`
> echo $score
71

Franklin52 (and OP) --
Yep... completely read over your comment about bc not available.

Last edited by joeyg; 12-03-2008 at 10:44 AM..
    #4  
Old Unix and Linux 12-03-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 6 July 2015, 11:27 AM EDT
Location: The Netherlands
Posts: 7,731
Thanks: 129
Thanked 546 Times in 514 Posts
joeyg,

The bc command isn't available for the OP.

Regards
Sponsored Links
    #5  
Old Unix and Linux 12-03-2008
puddy's Unix or Linux Image
puddy puddy is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 3 December 2008, 7:44 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Fraklin52, that did the trick! Thanks so much for your help!
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert Regular decimals to Packed decimals mgirinath Shell Programming and Scripting 2 09-20-2008 09:27 AM
ctrl+S resulting in (i-search) in bash balaji280283 UNIX for Dummies Questions & Answers 3 05-13-2008 05:00 AM
Bash variables RichieFondel Shell Programming and Scripting 2 03-19-2008 10:21 PM
using sed on bash variables (or maybe awk?) rev66 Shell Programming and Scripting 2 03-13-2008 11:17 PM
Multiplying Floats/Decimals rleebife Shell Programming and Scripting 10 08-02-2007 05:22 AM



All times are GMT -4. The time now is 07:04 AM.