lunedì 5 marzo 2012

Arithmetic calculation on real numbers in Ksh Script

Today a simple program to execute arithmetic calculation with ksh script :

#!/bin/ksh
echo "Enter the Price of the item \$ \c"
read price
echo "What Percentage of discount is available \c"
read per
echo "Your Total Savings are \c"
sav=`echo "scale=3\n(($price * $per) / 100)" | bc -l`
echo $sav

Is important see this command :

sav=`echo "scale=3\n(($price * $per) / 100)" | bc -l`

With "scale=3" we are fixing number of decimals to print.
With "bc -l" we are calculating with unix command bc the discout applied, with
($price * $per) / 100.

Stay tuned.


Nessun commento:

Posta un commento

Check Mid Year Objectives

Hi all Today middle year check of my 2026's goals. 1. ENGLISH Improve listening comprehension (So and So)   See at least one or two film...