Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using expr

Status
Not open for further replies.
Jun 2, 2004
24
US
How do I get `expr` to recognize a decimal?
Say I want to multiply some whole number by .05.

expr 50000 \* .05

On my Sun OS 5.6 machine, this command yields:
"expr: syntax error"

I also tried protecting the dot, but that did not help either.
Perhaps there are other soutions. Thanks in advance.
 
man bc

echo '50000 * 0.05' | bc


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
echo $((500 * 5))
works too, but only for integer values, which seems to be true for 'expr' too.

So use bc as shown above, or
Code:
echo "scale=2; 17/3" | bc
to get two decimal-digits, if you have bc.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top