Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

bash: dividing/multiplying variables resulting in decimals

Shell Programming and Scripting


Tags
bash

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
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
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: 25 November 2016, 10:15 AM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 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: 29 November 2016, 1:38 PM EST
Location: Within two miles of a Dunkin donuts.
Posts: 2,413
Thanks: 102
Thanked 177 Times in 163 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 11: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: 25 November 2016, 10:15 AM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 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

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 10:27 AM
ctrl+S resulting in (i-search) in bash balaji280283 UNIX for Dummies Questions & Answers 3 05-13-2008 06:00 AM
Bash variables RichieFondel Shell Programming and Scripting 2 03-19-2008 11:21 PM
using sed on bash variables (or maybe awk?) rev66 Shell Programming and Scripting 2 03-14-2008 12:17 AM
Multiplying Floats/Decimals rleebife Shell Programming and Scripting 10 08-02-2007 06:22 AM



All times are GMT -4. The time now is 01:42 AM.