Register
It is currently Sun Oct 26, 2014 12:57 am

Floating point calculations to two decimal places


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed May 18, 2005 7:25 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
jbsnake and I worked this out one night on irc for a project that required floating point calculations to two decimal places. IE: Money. ;)

Code:
CalcFloat ()
{
newNumber=`bc -l 2> /dev/null<< EOF
scale = 2
${1} ${2} ${3}
EOF
`
}


use by calling CalcFloat ()

Code:
CalcFloat $var1 \+ $var2
var3=$newNumber


One calculation - you can add,subtract,mult,divide ..... remember to use the \ before the operator.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP