The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
different result on shell and on perl HELP NEEDED nookie Shell Programming and Scripting 2 04-14-2008 09:18 PM
The shell script is not returning proper result clnsharma123 AIX 1 01-25-2008 01:54 AM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 07:43 PM
How to store query multiple result in shell script variable(Array) div_Neev Shell Programming and Scripting 4 11-06-2007 05:10 PM
running 2 shell jobs while waitting for result eyalush Shell Programming and Scripting 2 05-23-2005 05:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-08-2008
Registered User
 

Join Date: Jan 2008
Location: india
Posts: 3
Could any one tell me how to do get result in fraction in shell script

Could any one tell me how to do get result in fraction in shell script.

I am using expr for division of 2 number but it is giving Quitent.

I need it in full fraction value.

please helpp. how to do it using "dc" or "bc"
Reply With Quote
Forum Sponsor
  #2  
Old 01-08-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
$echo "10/3"|bc -l
3.33333333333333333333
Reply With Quote
  #3  
Old 01-08-2008
Registered User
 

Join Date: Jan 2008
Location: india
Posts: 3
Thumbs down If used in awk

How to set the precision in it any gud document on net in this regard... could help me!!! and also if using in awk do this will work, if not then how to make any approach over their??
Reply With Quote
  #4  
Old 01-08-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
I am not sure what u want. You can user printf to print the result with desired precision.
Eg:
echo "10/3"|bc -l|xargs printf "%.2f"

In awk the syntax for printf is similar to the printf in C,C++
Reply With Quote
  #5  
Old 01-09-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by Neerajjaiswal View Post
How to set the precision in it any gud document on net in this regard... ?
Code:
# echo "scale=4;10/3" | bc
3.3333
look up the man page of bc for a start.
Reply With Quote
  #6  
Old 01-09-2008
Registered User
 

Join Date: Jan 2008
Location: india
Posts: 3
working on long variable

Hi,

i am working very long variable.

do that way things will work???

ie 1238123781273761273/12368128273871238
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0