DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Simple Floating Point Calculator

04.07.2007
| 2616 views |
  • submit to reddit
        // Simple floating point calculator

#!/bin/bash

# CalcFloat function borrowed from crouse @ bashscripts.org
function CalcFloat () {
newNumber=`bc -l 2> /dev/null<< EOF
scale = 2
${1} ${2} ${3}
EOF
`
}

function fcalc () {
CalcFloat $num1 \ $oper $num2
answer=$newNumber
echo $answer
}

num1=$1
oper=$2
num2=$3
fcalc