bash: dividing/multiplying variables resulting in decimals | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

bash: dividing/multiplying variables resulting in decimals

Shell Programming and Scripting


Tags
bash

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-02-2008
puddy's Avatar
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 12-03-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 28 July 2014, 1:54 PM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 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 12-03-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 29 July 2014, 10:45 AM EDT
Location: Out running a Marathon.
Posts: 2,321
Thanks: 68
Thanked 153 Times in 142 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 12-03-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 28 July 2014, 1:54 PM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 Posts
joeyg,

The bc command isn't available for the OP.

Regards
Sponsored Links
    #5  
Old 12-03-2008
puddy's Avatar
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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:48 PM.