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
Converting Binary decimal coded values to Ascii Values gaur.deepti UNIX for Advanced & Expert Users 3 04-02-2008 09:33 AM
Help In Calculation of large values in loop sandeepb Shell Programming and Scripting 6 09-13-2007 05:02 AM
large files? ranj@chn UNIX for Dummies Questions & Answers 2 11-29-2006 03:55 AM
large file in AIX 4.3 alzenir Filesystems, Disks and Memory 1 12-08-2005 12:03 PM
Large files sehgalniraj UNIX for Dummies Questions & Answers 4 03-31-2005 05:03 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-19-2005
Registered User
 

Join Date: Mar 2005
Posts: 22
How to add two large values

Hi,

Gives me wrong value when,

$ echo `expr 2221753117 + 299363384`
-1773850795

How to overcome this?

Appreciate any help on this.

-Om
Reply With Quote
Forum Sponsor
  #2  
Old 05-19-2005
Registered User
 

Join Date: May 2005
Posts: 19
#/bin/ksh
number1=9888673663678977
number2=79872372378273472379837
result=`bc << EOF
$number1 + $number2
EOF`
echo "$number1 + $number2 = $result"



Try this script.
Reply With Quote
  #3  
Old 05-20-2005
Registered User
 

Join Date: Mar 2005
Posts: 22
Thanks for your script. It helped me a lot today.......

Thanks Again.
-Om
Reply With Quote
  #4  
Old 05-21-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
or more simply
result=`echo "2221753117 + 299363384" | bc`

Cheers
ZB
Reply With Quote
  #5  
Old 06-09-2005
r2007's Avatar
Registered User
 

Join Date: Jun 2005
Location: China
Posts: 73
or
Code:
dc -e '2221753117 299363384+p'
Reply With Quote
  #6  
Old 06-10-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
You can simply try as,

echo $((2221753117 + 299363384))

hth.
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 11:54 PM.


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