Over a million developers have joined DZone.

Simple Floating Point Calculator

·
// 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
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}