Sapiens Search

How to use floating numbers in Shell Script?

<variable> =`echo "scale=<precision>;<operations>"`

Example:

Write a code file named float as follow:

#!/bin/sh
floatNumber=`echo "scale=2;1/2" | bc`
echo $floatNumber

When you run it, the result will be:
$./float
.50

No comments:

Post a Comment